zsh-users
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: zsh-users@sunsite.dk
Subject: Re: set -A
Date: Fri, 7 Feb 2003 16:48:56 +0000	[thread overview]
Message-ID: <1030207164856.ZM25338@candle.brasslantern.com> (raw)
In-Reply-To: <12330.1044614892@csr.com>

On Feb 7, 10:48am, Peter Stephenson wrote:
}
} "Bart Schaefer" wrote:
} > If you've unset arr, then arr is not an array, and hence ${arr[@]} is
} > not an array either, and therefore "${arr[@]}" does not behave like
} > an array; rather, it behaves like a string, so putting it in double
} > quotes yields the empty string.
} 
} But the `@' subscript is not documented to do anything useful for
} strings

That's not strictly true.  The docs say, in consecutive paragraphs:

----------
A subscript of the form `[*]' or `[@]' evaluates to all elements of an
array; there is no difference between the two except when they appear
within double quotes. [...]

Subscripting may also be performed on non-array values, in which case
the subscripts specify a substring to be extracted.
----------

} nor can I see why anyone would assume it was useful in that case

It does NOT say that subscripting non-array values is limited to using
integer ranges; it just says "subscripting may also be performed."

} nor, if they *did* think, that why they would assume that it
} produced a null string instead of the usual elision of the argument.
} (I haven't put that very well.)

You put it well enough, and that last is a valid point.  Since for
foo=(x y z) we have "$foo[@]" equivalent to "x" "y" "z", then given
foo=xyz, should the expectation be that "$foo[@]" is "x""y""z" ?
(Note no word breaks between the quoted substrings.)  That might have
some pretty bizarre side-effects for nested expansions.

} I think we could safely and consistently have a non-existent parameter
} treated as an array in this special case without any negative impact.

It's actually worse than that, though, because ksh treats ALL parameters
as arrays -- in ksh, foo=xyz is the same as foo=(xyz) in zsh, and the
fiction of string variables is maintained by making $foo a reference to
${foo[0]}.  So when KSH_ARRAYS is set, ${foo[1]} (or any number greater
than zero) ought to produce an empty result when used on a scalar.


  reply	other threads:[~2003-02-07 16:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-07  0:01 Paul Ackersviller
2003-02-07  3:53 ` Bart Schaefer
2003-02-07 10:48   ` Peter Stephenson
2003-02-07 16:48     ` Bart Schaefer [this message]
2003-02-07 17:36       ` Peter Stephenson

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=1030207164856.ZM25338@candle.brasslantern.com \
    --to=schaefer@brasslantern.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).