From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21840 invoked from network); 4 May 2004 17:46:04 -0000 Received: from thor.dotsrc.org (HELO a.mx.sunsite.dk) (qmailr@130.225.247.86) by ns1.primenet.com.au with SMTP; 4 May 2004 17:46:04 -0000 Received: (qmail 18685 invoked from network); 4 May 2004 17:43:12 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 4 May 2004 17:43:12 -0000 Received: (qmail 24909 invoked by alias); 4 May 2004 17:43:03 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7437 Received: (qmail 24855 invoked from network); 4 May 2004 17:43:02 -0000 Received: from thor.dotsrc.org (HELO a.mx.sunsite.dk) (qmailr@130.225.247.86) by sunsite.dk with SMTP; 4 May 2004 17:42:59 -0000 Received: (qmail 9070 invoked from network); 4 May 2004 17:38:11 -0000 Received: from madrid10.amenworld.com (62.193.203.32) by a.mx.sunsite.dk with SMTP; 4 May 2004 17:38:09 -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 i44Hc6k32118 for ; Tue, 4 May 2004 19:38:06 +0200 Received: from raul@pleyades.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <1BL3sH-0001ML-00>; Tue, 4 May 2004 19:38:33 +0200 Date: Tue, 4 May 2004 19:38:33 +0200 From: DervishD To: Zsh Users Subject: Living without zsh: command line parsing Message-ID: <20040504173833.GB4794@DervishD> Mail-Followup-To: Zsh Users Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 :) First of all, sorry for the length of the following message and for being a bit off-topic, but I don't know anyone in the free software world who knows more of shell scripting that you. So please be patient with me O:) I have a problem with a free software project I'm making, where I must process certain command line and store some values in a variable depending on that command line. The problem is that I must do it so it works with a Single Unix Specification V3 compliant shell, I want to know how. If anyone has curiosity, all this is related with the upcoming new version of MOBS, a building framework I use for my projects, published in my homepage. 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" ;; Well, this works, because when I use 'XDEFS' in the compilation I have a series of -D and -U and only the lasts have effect, but what I want is to have just one copy, that is, I want to have just one set of '-D' and '-U' relating the $argument, the last one in fact. I have the following limitations: - The syntax must be SUSv3 compatible, so no Zsh tricks :( - XDEFS is used for more options, so I cannot just throw away it. - I can have any number of --enable or --disable options with the same $argument. - They can come in any order, interspersed with other options. I'm sure that there is a simple solution that I'm missing completely that is far better than the duplication I'm currently making :(( Thanks a lot in advance :) If anyone wants to take a look at the latest stable release of this project, which is no much different than the development one, it is GPL'd and can be got in my homepage (see the signature below). It's called MOBS (My Own Building System). Raúl Núñez de Arenas Coronado -- Linux Registered User 88736 http://www.pleyades.net & http://raul.pleyades.net/