Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Stripping spaces from a shell variable, portably
- X-seq: zsh-workers 19159
- From: DervishD <raul@xxxxxxxxxxxx>
- To: Zsh <zsh-workers@xxxxxxxxxx>
- Subject: Re: Stripping spaces from a shell variable, portably
- Date: Wed, 1 Oct 2003 16:00:09 +0200
- In-reply-to: <20031001095005.GA22203@xxxxxxxxxxxxxxxxx>
- Mail-followup-to: Zsh <zsh-workers@xxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- Organization: Pleyades
- References: <20031001092757.GA31207@DervishD> <20031001095005.GA22203@xxxxxxxxxxxxxxxxx>
Hi Thomas :)
* Thomas Köhler <jean-luc@xxxxxxxxxxxxxxxxx> 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/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author