Lets write our first Hello world shell script. You can use any text editor like notepad++ or can use vi to create and edit the files.
If you are using vi command then just write vi with file name –
it will create an test.sh file on specified location and will open an vi editor, to write press i, it will come in input mode. Now, write you first Hello world shell script-
# This is my first script.
echo "Hello World"
Now save the file and close it by hitting Escape followed by “:wq” and Return.
The first line of the file tells unix which shell to use to execute the file. /bin/sh is the default location for the bourne shell. It’s called a shebang because the # symbol is called a hash, and the ! symbol is called a bang.
The second line begins with a special symbol: #. This marks the line as a comment, and it is ignored completely by the shell.
To execute the script run the following command if you are in same directory –
It will show the output as Hello World. It’s our first unix shell script.
Please write your suggestion in comment box. I will come up with more shell script tutorials in upcoming days. Thanks.