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

[PATCH] (final) unset "array[$anything]"



Here's the diff just for "literal" unset, omitting all the
alternatives and omitting the problematic hunk that modified getasg().

I've included a NEWS entry, but have not yet attempted to create an
incompatibilities section for README since it's not clear what the
next zsh version number will be.
diff --git a/NEWS b/NEWS
index ee97868f9..c12ec3b0e 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,18 @@ Note also the list of incompatibilities in the README file.
 Changes since 5.8
 -----------------
 
+When unsetting a hash element, the string enclosed in square brackets is
+interpreted literally after any normal command-line-argument expansions.
+Thus
+  unset "hash[$key]"
+first expands $key as usual for a double-quoted string, and then interprets
+that result as the exact hash element to unset.  This differs from previous
+versions of the shell, which would also remove a leading backslash for an
+unusual subset of characters in the expansion of $key.  Note this also
+means, for example, that
+  unset 'hash[ab]cd]'
+unsets the element with key "ab]cd" rather than silently doing nothing.
+
 The function command learnt a -T option to declare a function and enable
 tracing for it simultaneously.
 
diff --git a/Src/builtin.c b/Src/builtin.c
index a16fddcb7..d7d2ea297 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3724,14 +3724,12 @@ bin_unset(char *name, char **argv, Options ops, int func)
     while ((s = *argv++)) {
 	char *ss = strchr(s, '['), *subscript = 0;
 	if (ss) {
-	    char *sse;
+	    char *sse = ss + strlen(ss)-1;
 	    *ss = 0;
-	    if ((sse = parse_subscript(ss+1, 1, ']'))) {
+	    if (*sse == ']') {
 		*sse = 0;
 		subscript = dupstring(ss+1);
 		*sse = ']';
-		remnulargs(subscript);
-		untokenize(subscript);
 	    }
 	}
 	if ((ss && !subscript) || !isident(s)) {


Messages sorted by: Reverse Date, Date, Thread, Author