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

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