Unix Shell Script basics -Hello World- Beginners Guide
|I heard a lot about shell script, so I decided to learn some basics of UNIX shell script.
Shell provides an interface to UNIX system and collect inputs and executes program based on that inputs.
A UNIX shell script basically a text file that contain a group of commands that is executed one by one at UNIX operating system command prompt.
I have windows system, so i need to figure out the Linux’s bash alternative.
I will use Cygwin for windows as its best for window platform. You can download Cygwin from here.
Visit to understand What is shell in unix ?
Unix Shell Script Example
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 –
vi test.sh
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-
#!/bin/sh # 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 –
sh test.sh
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.