From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7337 invoked from network); 1 Oct 2003 09:27:20 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 1 Oct 2003 09:27:20 -0000 Received: (qmail 28830 invoked by alias); 1 Oct 2003 09:26:59 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 19157 Received: (qmail 28818 invoked from network); 1 Oct 2003 09:26:58 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 1 Oct 2003 09:26:58 -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 9:26:58 -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 h919Qvt32639 for ; Wed, 1 Oct 2003 11:26:57 +0200 Received: from raul@pleyades.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <1A4dH3-00087R-00>; Wed, 1 Oct 2003 11:27:57 +0200 Date: Wed, 1 Oct 2003 11:27:57 +0200 From: DervishD To: Zsh Subject: Stripping spaces from a shell variable, portably Message-ID: <20031001092757.GA31207@DervishD> Mail-Followup-To: Zsh Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.4i Organization: Pleyades User-Agent: Mutt/1.4i Hi all :)) I need to strip leading and trailing spaces from the contents of a shell variable, and I need to do it portably, with a construct like ${...%% } and with no loops. When I say 'portably' I mean using SuSv3 constructs, not Zsh extensions. I've tried the obvious ${variable# } for stripping a single space, but this needs a while loop, which I want to avoid (although it seems to be portable): while [ "$variable" != "${variable# }" ] do variable="${variable# }" done And the same with the '%' construct. Please note that I cannot use '[[' for the test, since it must be portable, and this involves exec'ing the 'test' binary for each space in the variable :(( If no solution is possible I'll use 'tr', because the shell code must run in bash and zsh at least, but I really want it to be able to run in any SuSv3 compliant shell. Thanks a lot for your help :) Raúl Núñez de Arenas Coronado -- Linux Registered User 88736 http://www.pleyades.net & http://raul.pleyades.net/