My First Shell script
We are about to write a script for Hello World. After that we will have some flavors of Hello World Program. First let us create a shell script file named. HelloWorld.sh
#!/bin/sh #This is a comment line! echo Hello World #This is also Comment line.
In this the first line says Unix that the file is to be executed using /bin/sh. This is where Bourne Shell is located.
The Second line is an comment which begins with a special symbol #. This marks the line as a comment, and it is ignored completely by the shell.
The only exception is when the very first line of the file starts with #! - as ours does and this is special derivative. So, if you are using csh, ksh or any other shell it would be interpreted by the Bourne Shell (/bin/sh).
The third line runs a command named echo, with two parameters, or argument i.e. "Hello" and the second is "World".
Now let us give permission to first.sh and then run by following way
Giving Permission: chmod 777 first.sh
Running Shell Script: ./first.sh
or you may also run as: sh first.sh
sh-4.3$ chmod 777 first.sh sh-4.3$ sh first.sh Hello World!
You may probably expect the output from terminal itself as...
sh-4.3$ echo Hello World Hello World sh-4.3$
Now Let us View some more examples on echo ...
#!/bin/sh #This is a comment! echo "Hello World" #This is a comment, Too! echo "Too many Space" echo Too many Space echo "Star * Between" echo Star * Between echo "quotes" noquotes echo Spaces " " Between echo "Quotes"*"Star" echo `hello` world echo 'hello' world
You May run the above program on the following link given below.
Program Link : https://goo.gl/qgNoMp
This is Just the beginning... If you want know more about it do comment me.. Also, we might use more powerful command than echo in future.
Regards,
Niraj Bhagchandani
Niraj Bhagchandani
0 comments:
Post a Comment