zsh-users
 help / color / mirror / code / Atom feed
From: danielwallace <danielwallace@gtmanfred.com>
To: TJ Luoma <luomat@gmail.com>, Zsh-Users List <zsh-users@zsh.org>
Subject: RE: Processing Arguments
Date: Tue, 3 Dec 2013 16:49:37 -0600	[thread overview]
Message-ID: <BAY404-EAS4114D257B427794C8DF6512ABD50@phx.gbl> (raw)

[-- 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.






             reply	other threads:[~2013-12-03 22:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-03 22:49 danielwallace [this message]
2013-12-04  7:27 ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
2013-12-03 22:44 TJ Luoma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BAY404-EAS4114D257B427794C8DF6512ABD50@phx.gbl \
    --to=danielwallace@gtmanfred.com \
    --cc=luomat@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).