Let's say this is my script:
#!/bin/sh
# source shflags
. shflags
# define a 'name' command-line string flag
DEFINE_string 'name' 'world' 'name to say hello to' 'n'
# parse the command-line
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
# say Hello!
echo "Hello, ${FLAGS_name}!"
For using --help (or -h) I can see the usage/help:
USAGE: ./sample.sh [flags] args
flags:
-n,--name: name to say hello to (default: 'world')
-h,--[no]help: show this help (default: false)
However I'd like to display the same usage/help (shflags constructed) also in case of no arguments provided to script. Any idea how can I do so?
I've tried adding:
if [ $# == 0 ] ; then
echo $USAGE
exit 1;
fi
Well, the detection of no args works, but I have nothing printed.
UPDATE:
shflags version refered is available on: http://code.google.com/p/shflags/source/browse/tags/1.0.3/src/shflags