bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bash getopts option


From: Matthew Woehlke
Subject: Re: Bash getopts option
Date: Wed, 28 Feb 2007 10:15:54 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.9) Gecko/20061206 Thunderbird/1.5.0.9 Mnenhy/0.7.4.0

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]