Skip to content
Justice Tech School

Script Arguments

$1 to $9 are arguments, $# counts them, $@ lists them and shift removes the first.

Example
set -- one two three
echo "$# $1 $2"
shift
echo "$@"
for a in "$@"; do echo "arg: $a"; done

Result

3 one two
two three
arg: two
arg: three

Exercise

Count args.

echo $

Quiz Test

What does shift do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.