Shanks wrote:
I am trying to parse command line options using getopts. for parsing options that are words , for e.g -help, Bash is not allowing me
to do that.
while getopts c:d:fh:help options
do
case $options in help) echo" Help"
                ;;
done
The above code does not parse -help option. Any suggestions

I don't think getopts knows how to parse words as options (and not as non-GNU-style, certainly). You are probably better off writing your own parser, something like this:

while [ $1 ] ; do
        [ ${1:0:1} = '-' ] || break
        case ${1:1} in
                help) echo help;;
                c*)
                        if [ ${1:1} ] ; then arg=${1:1}
                        else shift; arg=$1
                        fi
                        echo "arg of -c is $arg"
                        ;;
                *)
                        echo "bad option, $1";;
        esac
        shift
done

--
Matthew
Obscurity: +5



_______________________________________________
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash

Reply via email to