Examples of passing arguments to the shell

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] This site maintained by unixhelp@math.rutgers.edu
This page was last updated on September 05, 2006 at 10:30 am and is maintained by webmaster@math.rutgers.edu.
For questions regarding courses and/or special permission, please contact mclausen@math.rutgers.edu.
For questions or comments about this site, please contact help@math.rutgers.edu.
© 2012 Rutgers, The State University of New Jersey. All rights reserved.