< Previous | Contents | Next >
Determining The Number of Arguments
The shell also provides a variable, $#, that contains the number of arguments on the com- mand line:
#!/bin/bash
# posit-param: script to view command line parameters echo "
#!/bin/bash
# posit-param: script to view command line parameters echo "
Number of arguments: $#
\$0 = $0
\$1 = $1
\$2 = $2
\$3 = $3
\$4 = $4
\$5 = $5
\$6 = $6
\$7 = $7
\$8 = $8
\$9 = $9 "
The result:
[me@linuxbox ~]$ posit-param a b c d
Number of arguments: 4
$0 = /home/me/bin/posit-param
$1 = a
$2 = b
$3 = c
$4 = d
$5 =
$6 =
$7 =
$8 =
$9 =