summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilippe Altherr <philippe.altherr@gmail.com>2026-08-22 17:00:11 -0700
committerBart Schaefer <schaefer@zsh.org>2026-08-22 17:00:11 -0700
commit556479e8eb744b0c0f7605d1f2ca8de799f3b16c (patch)
tree0717a70c0b0e8cbc473a9c2c001eaa8f783fad6c
parent55026: Fix ${(!)ref::=var} substitutions for symmetry with other flags (diff)
downloadzsh-556479e8eb744b0c0f7605d1f2ca8de799f3b16c.tar
zsh-556479e8eb744b0c0f7605d1f2ca8de799f3b16c.tar.gz
zsh-556479e8eb744b0c0f7605d1f2ca8de799f3b16c.tar.bz2
zsh-556479e8eb744b0c0f7605d1f2ca8de799f3b16c.tar.lz
zsh-556479e8eb744b0c0f7605d1f2ca8de799f3b16c.tar.xz
zsh-556479e8eb744b0c0f7605d1f2ca8de799f3b16c.tar.zst
zsh-556479e8eb744b0c0f7605d1f2ca8de799f3b16c.zip
55047 (first part): Revert ${!var} in ksh mode to remove namref special case
-rw-r--r--Src/subst.c2
-rw-r--r--Test/K01nameref.ztst55
-rw-r--r--Test/K02parameter.ztst17
3 files changed, 71 insertions, 3 deletions
diff --git a/Src/subst.c b/Src/subst.c
index 254408ea6..94a07b27e 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -2118,7 +2118,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
* handle this with the ^, =, ~ stuff, below.
*/
if ((c = *s) == '!' && s[1] != Outbrace && EMULATION(EMULATE_KSH)) {
- hkeys = SCANPM_WANTKEYS|SCANPM_NONAMEREF;
+ hkeys = SCANPM_WANTKEYS;
s++;
/* There's a slew of other special bash meanings of parameter
* references that start with "!":
diff --git a/Test/K01nameref.ztst b/Test/K01nameref.ztst
index 22aacc8e9..342edf5a4 100644
--- a/Test/K01nameref.ztst
+++ b/Test/K01nameref.ztst
@@ -2407,4 +2407,59 @@ F:converting from association/array to string should work here too
typeset -Hn ref_H
0:unsusual but legal option combinations
+ typeset str0=abc
+ typeset -a arr0=(aa bb cc)
+ typeset -A hsh0=([0]=aa [1]=bb [2]=cc)
+ typeset -n str1=str0 arr1=arr0 hsh1=hsh0
+ typeset -n str2=str1 arr2=arr1 hsh2=hsh1
+ emulate ksh -c '
+ echo "${str0} - ${str1} - ${str2}"
+ echo "${str0[1]} - ${str1[1]} - ${str2[1]}"
+ echo "${str0[1,2]} - ${str1[1,2]} - ${str2[1,2]}"
+ echo "${str0[@]} - ${str1[@]} - ${str2[@]}"
+ echo "${arr0} - ${arr1} - ${arr2}"
+ echo "${arr0[1]} - ${arr1[1]} - ${arr2[1]}"
+ echo "${arr0[1,2]} - ${arr1[1,2]} - ${arr2[1,2]}"
+ echo "${arr0[@]} - ${arr1[@]} - ${arr2[@]}"
+ echo "${hsh0} - ${hsh1} - ${hsh2}"
+ echo "${hsh0[1]} - ${hsh1[1]} - ${hsh2[1]}"
+ echo "${hsh0[@]} - ${hsh1[@]} - ${hsh2[@]}"
+ echo
+ echo "${!str0} - ${!str1} - ${!str2}"
+ echo "${!str0[1]} - ${!str1[1]} - ${!str2[1]}"
+ echo "${!str0[1,2]} - ${!str1[1,2]} - ${!str2[1,2]}"
+ echo "${!str0[@]} - ${!str1[@]} - ${!str2[@]}"
+ echo "${!arr0} - ${!arr1} - ${!arr2}"
+ echo "${!arr0[1]} - ${!arr1[1]} - ${!arr2[1]}"
+ echo "$(exec 2>&1; echo ${!arr0[1,2]}) - $(exec 2>&1; echo ${!arr1[1,2]}) - $(exec 2>&1; echo ${!arr2[1,2]})"
+ echo "${!arr0[@]} - ${!arr1[@]} - ${!arr2[@]}"
+ echo "${!hsh0} - ${!hsh1} - ${!hsh2}"
+ echo "${!hsh0[1]} - ${!hsh1[1]} - ${!hsh2[1]}"
+ echo "${!hsh0[@]} - ${!hsh1[@]} - ${!hsh2[@]}"
+ '
+0:emulation of ksh's bang always dereferences the expanded parameter
+>abc - abc - abc
+>b - b - b
+>bc - bc - bc
+>abc - abc - abc
+>aa - aa - aa
+>bb - bb - bb
+>bb cc - bb cc - bb cc
+>aa bb cc - aa bb cc - aa bb cc
+>aa - aa - aa
+>bb - bb - bb
+>aa bb cc - aa bb cc - aa bb cc
+>
+>abc - abc - abc
+>b - b - b
+>bc - bc - bc
+>abc - abc - abc
+>aa - aa - aa
+>1 - 1 - 1
+>(eval):6: invalid subscript - (eval):6: invalid subscript - (eval):6: invalid subscript
+>aa bb cc - aa bb cc - aa bb cc
+>aa - aa - aa
+>1 - 1 - 1
+>0 1 2 - 0 1 2 - 0 1 2
+
%clean
diff --git a/Test/K02parameter.ztst b/Test/K02parameter.ztst
index f9f434b36..2ae711e76 100644
--- a/Test/K02parameter.ztst
+++ b/Test/K02parameter.ztst
@@ -93,12 +93,25 @@ F:Braces are required
() {
typeset -n .k02.ref=.k02.array
emulate -L ksh
- print -l ${!.k02.ref} ${(!).k02.ref} ${.k02.ref}
+ print -l ${!.k02.ref} ${(k).k02.ref} ${(!).k02.ref} ${.k02.ref}
+ print -l ${!.k02.ref[2]} ${(k).k02.ref[2]} ${(!).k02.ref[2]} ${.k02.ref[2]}
}
0:namerefs with namespaces
+F:ksh expands "${!.k02.ref}" to ".k02.ref" but ("${!ref}" when in namespace "k02") to "array"
+F:the former looks bogus; expanding to ".k02.array" looks more logical/consistent
+>characters
+>characters
>.k02.array
->.k02.array
+F:ksh expands "${.k02.ref}" to ".k02.array" but ("${ref}" when in namespace "k02") to "characters"
+F:the former looks bogus; expanding to "characters" looks more logical/consistent
>characters
+F:ksh expands "${!.k02.ref[2]}" and ("${!ref[2]}" when in namespace "k02") to "array[2]"
+>2
+>2
+F:"${(!).k02.ref[2]}" -> "${${:-.k02.array}[2]}" -> "0"
+>0
+F:ksh expands "${.k02.ref[2]}" and ("${ref[2]}" when in namespace "k02") to "an"
+>an
k.=empty
k.2=test