positional parameters

The numbered variables $1, $2 and so on that hold the arguments given to a script or function, with $# holding how many there are.

In more detail

Check $# before reading $1, and quote them as "$1" so an argument with spaces stays whole. Arguments past the ninth need braces, as in ${10}. At the prompt, set -- a b c replaces them so you can practise.

Examples

bash greet.sh Ada Grace
echo "first: $1, count: $#"

Related terms

Taught in

References