Our first script – Hello World

Since we have learned basic commands in the Linux OS, we will now write our first shell script called hello.sh. You can use any editor of your choice, such as vi, gedit, nano, emacs, geany, and other similar editors. I prefer to use the vi editor:

  1. Create a new hello.sh file as follows:
# This is comment line 
echo "Hello World" 
  1. Save the newly created file.

The #!/bin/bash line is called the shebang line. The combination of the characters # and ! is called the magic sequence. The shell uses this to call the intended shell, such as /bin/bash in this case. This should always be the first line in a shell script.

The next few lines in the shell script are self-explanatory:

  • Any line starting ...

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.