zsh-workers
 help / color / mirror / code / Atom feed
From: DervishD <raul@pleyades.net>
To: Zsh <zsh-workers@sunsite.dk>
Subject: Re: Stripping spaces from a shell variable, portably
Date: Wed, 1 Oct 2003 16:00:09 +0200	[thread overview]
Message-ID: <20031001140009.GB14969@DervishD> (raw)
In-Reply-To: <20031001095005.GA22203@picard.franken.de>

    Hi Thomas :)

 * Thomas Köhler <jean-luc@picard.franken.de> 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/


  reply	other threads:[~2003-10-01 14:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-01  9:27 DervishD
2003-10-01  9:50 ` Thomas Köhler
2003-10-01 14:00   ` DervishD [this message]
2003-10-01 15:14 ` Bart Schaefer
2003-10-01 19:49   ` DervishD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031001140009.GB14969@DervishD \
    --to=raul@pleyades.net \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).