Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] [DOC] typeset -LRZul don't apply to (associative) arrays
- X-seq: zsh-workers 41144
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [PATCH] [DOC] typeset -LRZul don't apply to (associative) arrays
- Date: Wed, 24 May 2017 13:20:49 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=hIov9eCt6EHayqK+b6AUIyUONkD7YXwLTMVzDoeQK7Q=; b=pydIGOCAzhp1TpV/lkyl5q8DtnIrAZ5q83Fx9egGiBxbJ/n+8eFAvxZ+k/ulPTIEYJ RzOsou2StVOM1YeWjSzCDrMfHnsY4VzHL64oH7d9FqdIZg2X8p55JIDMa4JkEZhJ3VVU +hsQs91lPrlv/O6RhK2VQpHzFzDUnCfK2MDU8jEnAL73L8UB8GHwU589w/ZVpUJoejXC /X8PfIek6wU3FCo2S9iq15u0ga240/sAgZvV8KWbt7dYC6NogYK7GSZh3pKECiaHc7Gk Oe0e0VebvYsu4dRrRnWMW2pTC10vHatH2cNgowTEd79fkl5d5EM/pxf9CO00ILmcQVU+ e2Bw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mail-followup-to: Zsh hackers list <zsh-workers@xxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
typeset -u (for uppercase) and others like -LRZul don't apply to
(associative) arrays:
$ typeset -au a
$ a=(a)
$ echo $a
a
Just as well IMO as it would cause confusion with -U, or worse
for the keys of associative arrays. People can (and probably
should always instead of using those ksh-style flags) use
parameter-expansion-flags instead (${(U)array}...).
Other option is to go the ksh93 way:
$ ksh93 -c 'typeset -a -u -R3 a; a=(a b); printf "<%s>\n" "${a[@]}"'
< A>
< B>
$ ksh93 -c 'typeset -A -u a; a=([a]=x [A]=y); for k in "${!a[@]}"; do printf "%s => %s\n" "$k" "${a[$k]}"; done'
A => Y
a => X
(for associative arrays, only the values are transformed, though
for elements whose values are arrays, that doesn't apply to the
values of those arrays:
$ ksh93 -c 'typeset -A -u a; a=([a]=x [b]=(n m)); echo "${a[a]}" "${a[b][0]}"'
X n
).
Doc patch attached for the current situation. I'd say it's
probably not worth mentioning that in the case of arrays tied to
scalars (typeset -T), only the expansion of the scalar one is
affected.
--
Stephane
diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 81687c7..0e26da3 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -2012,7 +2012,8 @@ enditem()
Attribute flags that transform the final value (tt(-L), tt(-R), tt(-Z),
tt(-l), tt(-u)) are only applied to the expanded value at the point
of a parameter expansion expression using `tt($)'. They are not applied
-when a parameter is retrieved internally by the shell for any purpose.
+when a parameter is retrieved internally by the shell for any purpose.
+They have no effect on array or associative array parameters.
The following attribute flags may be specified:
Messages sorted by:
Reverse Date,
Date,
Thread,
Author