Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] [DOC] typeset -LRZul don't apply to (associative) arrays



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