Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Living without zsh: command line parsing
- X-seq: zsh-users 7438
- From: DervishD <raul@xxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxxxxx>
- Subject: Re: Living without zsh: command line parsing
- Date: Wed, 5 May 2004 12:29:48 +0200
- In-reply-to: <20040504173833.GB4794@DervishD>
- Mail-followup-to: Zsh Users <zsh-users@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: Pleyades
- References: <20040504173833.GB4794@DervishD>
Hi all :)
I've found a solution, and I give here just in case someone has
the curiosity.
* DervishD <raul@xxxxxxxxxxxx> 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/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author