Use $# , which is equal to the number of arguments provided, for example:
if [ "$#" -ne 1 ] then echo "Usage: ..." exit 1 fi
Caution: note that inside the function this will be equal to the number of arguments passed to the function, not the script.
EDIT: As SiegeX pointed out in bash, you can also use arithmetic expressions in (( ... )) . This can be used as follows:
if (( $# != 1 )) then echo "Usage: ..." exit 1 fi
Adam Zalcman Jan 23 '12 at 8:23 2012-01-23 08:23
source share