zsh-workers
 help / color / mirror / code / Atom feed
From: DervishD <raul@pleyades.net>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh <zsh-workers@sunsite.dk>
Subject: Re: Stripping spaces from a shell variable, portably
Date: Wed, 1 Oct 2003 21:49:34 +0200	[thread overview]
Message-ID: <20031001194934.GA7520@DervishD> (raw)
In-Reply-To: <1031001151452.ZM21074@candle.brasslantern.com>

    Hi Bart :)

 * Bart Schaefer <schaefer@brasslantern.com> dixit:
> }     I need to strip leading and trailing spaces from the contents of
> } a shell variable, and I need to do it [...] using SuSv3
> } constructs, not Zsh extensions.
> What about:
> 	tmp="${variable##*[^ ]}"
> 	variable="${variable%${tmp}}"
> 	tmp="${variable%%[^ ]*}"
> 	variable="${variable#${tmp}}"

    You're an effin genius, Bart ;)) I didn't even thing about using
a temporary... I wrote a similar solution, but using Zsh nested
substitution feature (getting rid of the temporary) in two
assignments, one for stripping the leading, another for the trailing.

    Thanks a lot :)) This is for a shell based building system, just
like autoconf but without autodetection (by now) and easier for
developers (they don't need to learn almost anything), that will be
published, if possible, this month. It's working since some time, but
now I'm doing some cleanup, and I needed to sanitize the options and
other things in the code. Most of the trimming is just one space, but
in a few points there are more... Thanks for your help :)

    If everybody in the world used zsh, I would have had no problems
writing this building system... but unfortunately I must write it
portably :( At least is GPL'd ;)

    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 19:51 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
2003-10-01 15:14 ` Bart Schaefer
2003-10-01 19:49   ` DervishD [this message]

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=20031001194934.GA7520@DervishD \
    --to=raul@pleyades.net \
    --cc=schaefer@brasslantern.com \
    --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).