This tutorial will show you an example on using arguments to a unix shell script or programming. Here we will create a shell script file for showing the example.


Knowledge of unix

Now open a unix terminal and create a shell script file called The shell script file extension is .sh. Write the below content in file.

echo "My first name is $1"
echo "My last name is $2"
echo "Total number of arguments is $#"

In the above program you see how we are indicating command line arguments. $1 and $2 are the command line arguments passed along with the file name from unix command. The third line shows the total count of command line arguments passed to the program using the syntax $#.

Run the script

$ ./ Soumitra Roy
My first name is Soumitra
My last name is Roy
Total number of arguments is 2

We are assuming that the shell script file exists in the current directory. Here we are executing the shell script file from current directory using command ./ and we have passed two arguments – Soumitra and Roy. And here in the output you see how the argument’s value is displayed.

So you have got an idea on using arguments to a unix shell script from the above example.

Thanks for reading.


Leave a Reply

Your email address will not be published. Required fields are marked *