From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3376 invoked from network); 5 May 2004 10:31:25 -0000 Received: from thor.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.86) by ns1.primenet.com.au with SMTP; 5 May 2004 10:31:25 -0000 Received: (qmail 1467 invoked from network); 5 May 2004 10:30:38 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 5 May 2004 10:30:38 -0000 Received: (qmail 14670 invoked by alias); 5 May 2004 10:30:26 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7438 Received: (qmail 14652 invoked from network); 5 May 2004 10:30:25 -0000 Received: from thor.dotsrc.org (HELO a.mx.sunsite.dk) (qmailr@130.225.247.86) by sunsite.dk with SMTP; 5 May 2004 10:30:22 -0000 Received: (qmail 520 invoked from network); 5 May 2004 10:30:21 -0000 Received: from madrid10.amenworld.com (62.193.203.32) by a.mx.sunsite.dk with SMTP; 5 May 2004 10:30:19 -0000 Received: from DervishD.pleyades.net (212.Red-80-35-44.pooles.rima-tde.net [80.35.44.212]) by madrid10.amenworld.com (8.10.2/8.10.2) with ESMTP id i45AUHN28329 for ; Wed, 5 May 2004 12:30:18 +0200 Received: from raul@pleyades.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <1BLJeu-0001ex-00>; Wed, 5 May 2004 12:29:48 +0200 Date: Wed, 5 May 2004 12:29:48 +0200 From: DervishD To: Zsh Users Subject: Re: Living without zsh: command line parsing Message-ID: <20040505102948.GB5774@DervishD> Mail-Followup-To: Zsh Users References: <20040504173833.GB4794@DervishD> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20040504173833.GB4794@DervishD> User-Agent: Mutt/1.4.2.1i Organization: Pleyades X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=none autolearn=no version=2.63 X-Spam-Hits: 0.0 Hi all :) I've found a solution, and I give here just in case someone has the curiosity. * DervishD 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/