I have created a script which takes parameters and arguments. I want to insert the --help argument.
I already know how to parse normal arguments with -, but I don't know how to parse the -- ones.
to parse optiopns for test.sh -h
i use the following check
while getopts ":h" opt;
do
case $opt in
h ) {
echo "help!!!"
exit 1
} ;;
esac
done
But I want to have the option to call the script with test.sh --help
Thanks in advance.
P.S. I am using Ubuntu 12.04...but it doesn't really matter.
Apparently I can't answer my own question if I have so less rep. I found the solution in one of the .sh scripts from /usr/bin
if test $# = 1; then
case "$1" in
--help | --hel | --he | --h )
func_usage; exit 0 ;;
--version | --versio | --versi | --vers | --ver | --ve | --v )
func_version; exit 0 ;;
esac
fi
--version
partial match could be rewritten just as--v*)
(assuming you're okay with--vfoo
). – Chris Down Feb 17 at 2:21