ash: make "locak VAR" unset VAR (bash does that)
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 16 Mar 2014 17:41:11 +0000 (18:41 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 16 Mar 2014 17:41:11 +0000 (18:41 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c
shell/ash_test/ash-misc/local1.right [new file with mode: 0644]
shell/ash_test/ash-misc/local1.tests [new file with mode: 0755]

index 04ba447b1f2a9d7e8320389bcaff210d49c4e9f3..7a097c814c309777cf1cd6b2f925cd8c925d8401 100644 (file)
@@ -8960,6 +8960,9 @@ mklocal(char *name)
                        vp->flags |= VSTRFIXED|VTEXTFIXED;
                        if (eq)
                                setvareq(name, 0);
+                       else
+                               /* "local VAR" unsets VAR: */
+                               setvar(name, NULL, 0);
                }
        }
        lvp->vp = vp;
diff --git a/shell/ash_test/ash-misc/local1.right b/shell/ash_test/ash-misc/local1.right
new file mode 100644 (file)
index 0000000..a2d121d
--- /dev/null
@@ -0,0 +1,4 @@
+A1:'A'
+A2:''
+A3:''
+A4:'A'
diff --git a/shell/ash_test/ash-misc/local1.tests b/shell/ash_test/ash-misc/local1.tests
new file mode 100755 (executable)
index 0000000..b1e6750
--- /dev/null
@@ -0,0 +1,11 @@
+a=A
+f() {
+       local a
+       # the above line unsets $a
+       echo "A2:'$a'"
+       unset a
+       echo "A3:'$a'"
+}
+echo "A1:'$a'"
+f
+echo "A4:'$a'"