From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10762 invoked from network); 1 Oct 2003 09:54:06 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 1 Oct 2003 09:54:06 -0000 Received: (qmail 6276 invoked by alias); 1 Oct 2003 09:53:59 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 19158 Received: (qmail 6264 invoked from network); 1 Oct 2003 09:53:58 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 1 Oct 2003 09:53:58 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [193.141.110.11] by sunsite.dk (MessageWall 1.0.8) with SMTP; 1 Oct 2003 9:53:58 -0000 Received: from karnickel.franken.de (localhost [127.0.0.1]) by karnickel.franken.de (8.12.10/8.12.10) with ESMTP id h919rvgP009425 for ; Wed, 1 Oct 2003 11:53:57 +0200 (CEST) Received: (from uucp@localhost) by karnickel.franken.de (8.12.10/8.12.2/Submit) with UUCP id h919rvLC009424 for zsh-workers@sunsite.dk; Wed, 1 Oct 2003 11:53:57 +0200 (CEST) (envelope-from jean-luc@picard.franken.de) Received: by picard.franken.de (Postfix, from userid 1001) id 169BB5BAA2; Wed, 1 Oct 2003 11:50:06 +0200 (CEST) Date: Wed, 1 Oct 2003 11:50:06 +0200 From: Thomas =?iso-8859-1?Q?K=F6hler?= To: Zsh Subject: Re: Stripping spaces from a shell variable, portably Message-ID: <20031001095005.GA22203@picard.franken.de> Mail-Followup-To: Zsh References: <20031001092757.GA31207@DervishD> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="sm4nu43k4a2Rpi4c" Content-Disposition: inline In-Reply-To: <20031001092757.GA31207@DervishD> X-Operating-System: Linux X-Editor: VIM - Vi IMproved 6.2 http://www.vim.org/ X-IRC: tirc; Nick: jeanluc X-URL: http://jeanluc-picard.de/ User-Agent: Mutt/1.5.4i --sm4nu43k4a2Rpi4c Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, DervishD wrote [2003/10/01]: > Hi all :)) >=20 > 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. >=20 > 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): >=20 > while [ "$variable" !=3D "${variable# }" ] > do > variable=3D"${variable# }" > done >=20 > 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 :(( >=20 > 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. Why not variable=3D`echo "$variable" | sed -e 's/^ *//' -e 's/ *$//'` ? I'm not sure whether all versions of sed understand multiple "-e" arguments, so it might me necessary to use this: variable=3D`echo "$variable" | sed -e 's/^ *//' | sed -e 's/ *$//'` > Thanks a lot for your help :) >=20 > Ra=FAl N=FA=F1ez de Arenas Coronado Ciao, Thomas --=20 Thomas K=F6hler Email: jean-luc@picard.franken.de | LCARS - Linux <>< WWW: http://jeanluc-picard.de | for Computers IRC: jeanluc | on All Real PGP public key available from Homepage! | Starships --sm4nu43k4a2Rpi4c Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQE/eqNNTEYXWMJlHuYRAngqAJ9JFWbxC4Z4QHcr6txvLyVYwlEA/QCfVz6u Au29aKy6i41+FHmwUQF8Fwo= =SZO2 -----END PGP SIGNATURE----- --sm4nu43k4a2Rpi4c--