From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14903 invoked from network); 1 Oct 2003 14:00:46 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 1 Oct 2003 14:00:46 -0000 Received: (qmail 1326 invoked by alias); 1 Oct 2003 14:00:38 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 19159 Received: (qmail 1311 invoked from network); 1 Oct 2003 14:00:37 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 1 Oct 2003 14:00:37 -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 14:0:36 -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 h91E0Zt15241 for ; Wed, 1 Oct 2003 16:00:35 +0200 Received: from raul@pleyades.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <1A4hWT-0003tk-00>; Wed, 1 Oct 2003 16:00:09 +0200 Date: Wed, 1 Oct 2003 16:00:09 +0200 From: DervishD To: Zsh Subject: Re: Stripping spaces from a shell variable, portably Message-ID: <20031001140009.GB14969@DervishD> Mail-Followup-To: Zsh References: <20031001092757.GA31207@DervishD> <20031001095005.GA22203@picard.franken.de> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20031001095005.GA22203@picard.franken.de> User-Agent: Mutt/1.4i Organization: Pleyades User-Agent: Mutt/1.4i Hi Thomas :) * Thomas Köhler dixit: > Why not > variable=`echo "$variable" | sed -e 's/^ *//' -e 's/ *$//'` Because if possible I want to do it just with shell code, without external programs. In fact, instead of sed I would prefer do with 'tr', so the code is not dependant on sed. 'tr' won't do a good job if the variable contents have spaces (legal ones) interspersed, so if sed is the only solution I would prefer to have the nasty spaces instead. > I'm not sure whether all versions of sed understand multiple > "-e" arguments, so it might me necessary to use this: According to SuSv3 (since the shell script will be SuSv3 compliant, I'd better use it for sed, too), you can provide multiple -e options, so if I use 'sed' (not probable, as I tell in the last paragraph) I will use multiple -e arguments. Thanks anyway, Thomas. Really these kind of processes should be done by sed, not shell code, if you want portability, but in this particular case I prefer the loop: slower, nastier, but not dependent on sed (although sed should be present on every Unix system out there, specially SuSv3 compliant ones...). Raúl Núñez de Arenas Coronado -- Linux Registered User 88736 http://www.pleyades.net & http://raul.pleyades.net/