Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

RE: Processing Arguments



Try looking up zparseopts. It is along the same lines as bush's getopts.

Daniel


Sent via the Samsung GALAXY S®4, an AT&T 4G LTE smartphone

-------- Original message --------
From: TJ Luoma <luomat@xxxxxxxxx>
Date: 12/03/2013  4:47 PM  (GMT-06:00)
To: Zsh-Users List <zsh-users@xxxxxxx>
Subject: Processing Arguments

I'm sure there has to be a better way of doing this, but the way that I've done it has always worked for me, so I've never bothered to look further.

Here's what I do:


    ANOTHER=no
    SOMETHING=no

    for ARGS in "$@"
    do
        case "$ARGS" in
            -s|--something)
                    SOMETHING=yes
                    shift
            ;;

            -a|--another)
                    ANOTHER=yes
                    shift
            ;;

            -*|--*)
                    echo "  $NAME [warning]: Don't know what to do with arg: $1"
                    shift
            ;;

        esac

    done # for args

The only downside to this is that you can't combine arguments such as `-sa` you have to use `-s -a`

Am I right? Is there a better way?

TjL

ps - I'm not _overly_ concerned with "portability" to other shells. I write zsh scripts because I like what zsh has to offer.







Messages sorted by: Reverse Date, Date, Thread, Author