Examples of passing arguments to the shell

To pass several arguments from the command line to the shell:

   cat first_5args
   # This script echoes the first five arguments
   # supplied to the script
   echo The first five command line
   echo arguments are $1 $2 $3 $4 $5
   first_5args mines a pint john o.k.
   The first five command line
   arguments are mines a pint john o.k.

This passes the arguments represented by parameters $1 through $5 to the shell script.


To pass the value of each positional parameter to the shell script:

   cat printps
   # This script converts ASCII files to PostScript
   # and sends them to the PostScript printer ps1
   # It uses a local utility "a2ps"
   a2ps $* | lpr -Pps1
   printps elm.txt vi.ref msg

This processes the three files given as arguments to the command printps.


[Home] [Search] [Index]