0
while getopts htn: OPTION
do
        case ${OPTION} in
                t)  LIST='john mike smith' ;;
               n) LIST='rob peter joe' ;;
               h|*)  show_usage
                     exit 0
                     ;;
        esac
done
shift $(($OPTIND - 1))
args=$*

above is a snippet of code. i would like to use more than one character in my options e.g fname lname should count as 2 options instead of "while getopts htn: OPTION"
would like something like "while getopts fname lname: OPTION
How do i get getopts to work in that form.

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by sknake
0

See: http://www.mail-archive.com/bug-bash@gnu.org/msg02546.html

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.