Interactive Shell

The Bash shell is commonly used interactively: It lets you enter and edit commands, then executes them when you press the Return key. Many Unix-based and Unix-like operating systems use Bash as their default shell (notably Linux and macOS). The terminal automatically enters an interactive Bash shell process on startup.

Output Hello World by typing the following:

echo "Hello World"
#> Hello World  # Output Example

Notes


Non-Interactive Shell

The Bash shell can also be run non-interactively from a script, making the shell require no human interaction. Interactive behavior and scripted behavior should be identical – an important design consideration of Unix V7 Bourne shell and transitively Bash. Therefore anything that can be done at the command line can be put in a script file for reuse.

Follow these steps to create a Hello World script:

  1. Create a new file called hello-world.sh
touch hello-world.sh
  1. Make the script executable by running [chmod](<http://ss64.com/bash/chmod.html>)+x hello-world.sh
  2. Add this code:
#!/bin/bash
echo "Hello World"

Line 1: The first line of the script must start with the character sequence #!, referred to as shebang1. The shebang instructs the operating system to run /bin/bash, the Bash shell, passing it the script’s path as an argument.

E.g. `/bin/bash hello-world.sh`

Line 2: Uses the [echo](<https://www.gnu.org/software/bash/manual/bash.html#index-echo>) command to write Hello World to the standard output.

  1. Execute the hello-world.sh script from the command line using one of the following: