zsh-users
 help / color / mirror / code / Atom feed
* RE: Processing Arguments
@ 2013-12-03 22:49 danielwallace
  2013-12-04  7:27 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: danielwallace @ 2013-12-03 22:49 UTC (permalink / raw)
  To: TJ Luoma, Zsh-Users List

[-- Attachment #1: Type: text/plain, Size: 1287 bytes --]

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@gmail.com>
Date: 12/03/2013  4:47 PM  (GMT-06:00)
To: Zsh-Users List <zsh-users@zsh.org>
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.






^ permalink raw reply	[flat|nested] 3+ messages in thread
* Processing Arguments
@ 2013-12-03 22:44 TJ Luoma
  0 siblings, 0 replies; 3+ messages in thread
From: TJ Luoma @ 2013-12-03 22:44 UTC (permalink / raw)
  To: Zsh-Users List

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.






^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-12-04  7:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-03 22:49 Processing Arguments danielwallace
2013-12-04  7:27 ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
2013-12-03 22:44 TJ Luoma

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).