hush: fix shift + $0 bug; add testcase
authorDenis Vlasenko <vda.linux@googlemail.com>
Sun, 20 May 2007 22:22:18 +0000 (22:22 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sun, 20 May 2007 22:22:18 +0000 (22:22 -0000)
shell/hush.c
shell/hush_test/hush-misc/shift.right [new file with mode: 0644]
shell/hush_test/hush-misc/shift.tests [new file with mode: 0644]

index 0d260a762b7ad70ed1606a8b116127596368f4e6..107b821f83338324a54d9751c15f25d7f8035183 100644 (file)
@@ -952,7 +952,7 @@ static int builtin_shift(char **argv)
                n = atoi(argv[1]);
        }
        if (n >= 0 && n < global_argc) {
-               /* XXX This probably breaks $0 */
+               global_argv[n] = global_argv[0];
                global_argc -= n;
                global_argv += n;
                return EXIT_SUCCESS;
diff --git a/shell/hush_test/hush-misc/shift.right b/shell/hush_test/hush-misc/shift.right
new file mode 100644 (file)
index 0000000..afb90be
--- /dev/null
@@ -0,0 +1,2 @@
+./shift.tests abc d e
+./shift.tests d e
diff --git a/shell/hush_test/hush-misc/shift.tests b/shell/hush_test/hush-misc/shift.tests
new file mode 100644 (file)
index 0000000..17f2c9f
--- /dev/null
@@ -0,0 +1,6 @@
+if test $# = 0; then
+    exec "$THIS_SH" $0 abc "d e"
+fi
+echo $0 $1 $2
+shift
+echo $0 $1 $2