In this tutorial we will discuss about the topic The Beginners Guide to Shell Scripting.
I will explain you what the sha-bang (also known as shebang) is and will create and exec the Hello World script.
What is the sha-bang (shebang)?
The shebang is the “#!” at the head of your script. It tells the operating system that the file is a set of commands that can be interpreted with a certain program. Following the shebang is the path of the program that interprets the script.
Example of shebang lines:
If the shebang line is missing from your script, it will be interpreted by the default system shell (usually bash on Linux and csh on *BSD).
How to create your first script:
I will use vim to write this in the myscript.sh file:
$ vim myscript.sh
echo "Hello World!"
How to invoke the recently created script with source or bash:
Now that the script was created, let’s exec it:
$ source myscript.sh
OR: $ bash myscript.sh
You can also set rx permissions to your script and exec it as an executable file:
$ chmod +rx myscript.sh
$ chmod 555 myscript.sh
And exec it:
If you liked this , read the next shell scripting article.