zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-users@sunsite.dk (Zsh users list)
Subject: Re: field splitting behavior
Date: Wed, 28 Nov 2001 10:30:06 +0000	[thread overview]
Message-ID: <28922.1006943406@csr.com> (raw)
In-Reply-To: "Zefram"'s message of "Tue, 27 Nov 2001 19:21:34 GMT." <20011127192134.I8299@fysh.org>

Zefram wrote:
> Paul Lew wrote:
> >> var='foobar'
> >> echo ${(@)${(s/:/)var}[1]}
> >f
> >
> >So why it did field splitting on each character when there is no
> >separator ':' found?  I would expect 'foobar' on the output.
> 
> The result of the splitting is a single word "foobar", as you expect.
> This is then treated as a scalar, not an array, and so the [1] extracts
> the first character, instead of the first element.  The (@) doesn't do
> what you think it does (it only has an effect where double quotes are
> used).  I don't see any easy way to force the result of a ${(s...)...}
> to be treated as an array, so I'll have to leave that to the expansion
> wizards.

I can only think of the gross hack

  print ${${(s/:/):-${var}:rubbish}[1]}

which extends the string to make sure it produces an array.  It's somewhat
inconsistent that you sometimes get a scalar and sometimes an array.

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


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


      reply	other threads:[~2001-11-28 10:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-27 19:04 Paul Lew - remove nospam when reply
2001-11-27 19:21 ` Zefram
2001-11-28 10:30   ` Peter Stephenson [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=28922.1006943406@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).