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.
Hello World by typing the following:
echo "Hello World" #> Hello World # Output Example
[echo](<https://www.gnu.org/software/bash/manual/bash.html#index-echo>)is a Bash builtin command that writes the arguments it receives to the standard output. It appends a newline to the output, by default.
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:
#!/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.
hello-world.shscript from the command line using one of the following: