# Check for proper number of command line args.
EXPECTED_ARGS=1
E_BADARGS=65
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` {arg}"
exit $E_BADARGS
fi
- sandip's blog
- Login or register to post comments
# Check for proper number of command line args.
EXPECTED_ARGS=1
E_BADARGS=65
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` {arg}"
exit $E_BADARGS
fi
Comments
An easier way would be via parameter substitution:
: ${1?"Usage: $0 ARGUMENT"}
If parameter set, use it, else print error message.
Wouldn't that cause problems if the arguments passed were 0 and/or "" ?
Sandip,
your check doesn't seem to allow a * wildcard to pass the check as an argument - it simply seems not to be counted. Why is that? My script must be able to accept this.
Any ideas, or a possible fix?
Cheers,
J.
That is due to bash globbing.
Try prefixing the * with \ like \* or,
`set -f` to disable globbing and then run the script.