zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-users@sunsite.dk
Subject: Re: Splitting string to array removes pipe symbol
Date: Tue, 16 Dec 2003 10:51:29 +0000	[thread overview]
Message-ID: <11632.1071571889@csr.com> (raw)
In-Reply-To: "Vincent Stemen"'s message of "Tue, 16 Dec 2003 02:34:49 CST." <20031216083449.GA9113@quark.localdomain>

Vincent Stemen wrote:
> However, when the globsubst option is set, it removes the pipe '|'
> symbol when it does the split.  Here is the trace output.
> 
>   +./t:62> cmd=uncompress foobar | cpio -i --quiet --unconditional
>   +./t:63> cmd=( uncompress foobar cpio -i --quiet --unconditional )

You have null_glob (or maybe csh_null_glob) set.  `|' is split to a
single bar.  Evaluation of the words takes place as if all the elements
of the array are arguments, which is different from evaluating as a
command.  (This is inevitable --- the only way of doing it differently
would be to parse the line again completely from scratch after the
glob_subst.)  In this case, the `|' is treated the same as (|),
i.e. either nothing or nothing, and removed since nothing matches it.
(You'd normally need the parentheses to stop it being evaluated as a
pipe, but it can't be in an argument list.)

You can fix this particular problem by quoting,
  cmd=("${(@)=cmd}")
but only because that cancels the effect of glob_subst, so that `|' is
just an ordinary character.  This may not be what you want.  It's
likely to be very difficult to force the shell both to split a line into
words *and* to parse it again as a full command line without joining it
up again.

Most people would probably come up with something using `eval'.  What you
should do depends why you need to split it at all.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


  reply	other threads:[~2003-12-16 10:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-16  8:34 Vincent Stemen
2003-12-16 10:51 ` Peter Stephenson [this message]
2003-12-19  6:47   ` Vincent Stemen

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=11632.1071571889@csr.com \
    --to=pws@csr.com \
    --cc=zsh-users@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).