Examples of passing arguments to the shell

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

   $cat first_5args
   # This script echos 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.

2. 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.

Top document