From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15156 invoked from network); 1 Oct 2003 19:51:44 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 1 Oct 2003 19:51:44 -0000 Received: (qmail 12338 invoked by alias); 1 Oct 2003 19:51:33 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 19161 Received: (qmail 12248 invoked from network); 1 Oct 2003 19:51:31 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 1 Oct 2003 19:51:31 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [217.174.194.138] by sunsite.dk (MessageWall 1.0.8) with SMTP; 1 Oct 2003 19:51:30 -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 h91JpMt13146; Wed, 1 Oct 2003 21:51:23 +0200 Received: from raul@pleyades.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <1A4myc-0001xa-00>; Wed, 1 Oct 2003 21:49:34 +0200 Date: Wed, 1 Oct 2003 21:49:34 +0200 From: DervishD To: Bart Schaefer Cc: Zsh Subject: Re: Stripping spaces from a shell variable, portably Message-ID: <20031001194934.GA7520@DervishD> Mail-Followup-To: Bart Schaefer , Zsh References: <20031001092757.GA31207@DervishD> <1031001151452.ZM21074@candle.brasslantern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1031001151452.ZM21074@candle.brasslantern.com> User-Agent: Mutt/1.4i Organization: Pleyades User-Agent: Mutt/1.4i Hi Bart :) * Bart Schaefer dixit: > } I need to strip leading and trailing spaces from the contents of > } a shell variable, and I need to do it [...] using SuSv3 > } constructs, not Zsh extensions. > What about: > tmp="${variable##*[^ ]}" > variable="${variable%${tmp}}" > tmp="${variable%%[^ ]*}" > variable="${variable#${tmp}}" You're an effin genius, Bart ;)) I didn't even thing about using a temporary... I wrote a similar solution, but using Zsh nested substitution feature (getting rid of the temporary) in two assignments, one for stripping the leading, another for the trailing. Thanks a lot :)) This is for a shell based building system, just like autoconf but without autodetection (by now) and easier for developers (they don't need to learn almost anything), that will be published, if possible, this month. It's working since some time, but now I'm doing some cleanup, and I needed to sanitize the options and other things in the code. Most of the trimming is just one space, but in a few points there are more... Thanks for your help :) If everybody in the world used zsh, I would have had no problems writing this building system... but unfortunately I must write it portably :( At least is GPL'd ;) Raúl Núñez de Arenas Coronado -- Linux Registered User 88736 http://www.pleyades.net & http://raul.pleyades.net/