Create a script - Hello World

Follow these steps to create a Hello World script:

1. Create a new file called hello-world.sh using touch hello-world.sh

2. Make the script executable by running chmod +x hello-world.sh

3. Add this code:

#!/bin/bash 
echo "Hello World"

Explanation:

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 command to write Hello World to the standard output.

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

./hello-world.sh – most commonly used, and recommended 
/bin/bash hello-world.sh
bash hello-world.sh – assuming /bin is in your $PATH
sh hello-world.sh

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)