Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: set -A
- X-seq: zsh-users 5890
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: set -A
- Date: Fri, 7 Feb 2003 16:48:56 +0000
- In-reply-to: <12330.1044614892@xxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <12330.1044614892@xxxxxxx>
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author