How to use Positional Parameters in Shell Script

We can convey information to a program by specifying arguments at the command line. The shell uses Positional Parameters so that the shell script can know what has been passed to it. They are nine in number, named $1 through $9.

The set command is used to assign values to the positional parameters.

The following program shows the working of the positional parameters


#!/bin/sh

set Joys of Programming - Programming made easier and joyful

echo $1 $2 $3 $4 $5 $6 $7 $8 $9

Let’s see the output of the program


Joys of Programming - Programming made easier and joyful

The set command sets the value $1 with ‘Joys’, $2 with ‘of’ and so on. We have verified the values using the echo statement.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s