From: DervishD <raul@pleyades.net>
To: Zsh Users <zsh-users@sunsite.dk>
Subject: Re: Living without zsh: command line parsing
Date: Wed, 5 May 2004 12:29:48 +0200 [thread overview]
Message-ID: <20040505102948.GB5774@DervishD> (raw)
In-Reply-To: <20040504173833.GB4794@DervishD>
Hi all :)
I've found a solution, and I give here just in case someone has
the curiosity.
* DervishD <raul@pleyades.net> dixit:
> What I want to do, and I *really* need your help for that, is the
> following: I have a command line like, let's say
>
> $./0 --enable-feature1 --enable-feature2 --disable-feature1 ...
>
> I want to parse that command line and store some values in
> variables for that. I cannot depend on 'getopt', so I parse the
> command line using a case construct. When I parse the above command
> line, what I do now is something like:
>
> # Note that some code relating to checks is missing
> --enable*)
> argument="${option#--enable}"
> argument="${argument#-}"
> XDEFS="${XDEFS} -D_ENABLE_$argument -U_DISABLE_$argument" ;;
>
> --disable*)
> argument="${option#--disable}"
> argument="${argument#-}"
> XDEFS="${XDEFS} -D_DISABLE_$argument -U_ENABLE_$argument" ;;
Now I use the following:
--enable*)
argument="${option#--enable}"
argument="${argument#-}"
eval ENABLE_$argument=yes
eval unset DISABLE_$argument
FEATURES="$FEATURES $argument"
--disable*)
argument="${option#--disable}"
argument="${argument#-}"
eval DISABLE_$argument=yes
eval unset ENABLE_$argument
FEATURES="$FEATURES $argument"
And after doing the command line parsing I do:
FEATURES=`printf -- "$FEATURES"|tr -s ' ' '\n'|sort|uniq|tr -s '\n' ' '`
This way, 'FEATURES' contain a list of the selected features,
with no repeated ocurrences. This variable can be processed later
using a for loop. All is SUSv3 compliant AFAIK.
As I told the solution was simple but I was missing it.
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/
prev parent reply other threads:[~2004-05-05 10:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-04 17:38 DervishD
2004-05-05 10:29 ` DervishD [this message]
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=20040505102948.GB5774@DervishD \
--to=raul@pleyades.net \
--cc=zsh-users@sunsite.dk \
/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).