Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous contents
Next: Constructions Up: Shell Programming Previous: Wildcard characters   Contents

Arguments from the command line

It is easy to write a script that takes arguments (options) from the command line. Type this script into a file called args.
echo this $0 command has $# arguments.
echo They are $*

The echo command echoes the rest of the line to the screen by default. Within a shell script, $0 denotes the script's name, $1 denotes the first argument mentioned on the command line and so on. Make the script executable then try it out with various arguments. For example, if you type

    args first another

Tim Love 2010-04-27