aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-11-23 21:08:38 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-11-23 21:08:38 +0000
commitcccdc4e01abb354c50aa483a21d5ff56a18c0b4a (patch)
tree4290b391d3ea634a0393082c2233935bf5357afc /shell
parent835068637e81771a1b45b9faf04a31830f0e5d8a (diff)
downloadbusybox-w32-cccdc4e01abb354c50aa483a21d5ff56a18c0b4a.tar.gz
busybox-w32-cccdc4e01abb354c50aa483a21d5ff56a18c0b4a.tar.bz2
busybox-w32-cccdc4e01abb354c50aa483a21d5ff56a18c0b4a.zip
hush: fix $ expansion in redirections, add testcase for that
Diffstat (limited to 'shell')
-rw-r--r--shell/README3
-rw-r--r--shell/hush.c11
-rw-r--r--shell/hush_test/hush-vars/var_expand_in_redir.right3
-rwxr-xr-xshell/hush_test/hush-vars/var_expand_in_redir.tests13
-rwxr-xr-xshell/hush_test/run-all1
5 files changed, 27 insertions, 4 deletions
diff --git a/shell/README b/shell/README
index b86f96cf4..f78ed9d18 100644
--- a/shell/README
+++ b/shell/README
@@ -1,5 +1,8 @@
1Various bits of what is known about busybox shells, in no particular order. 1Various bits of what is known about busybox shells, in no particular order.
2 2
32007-11-23
4hush: fixed bogus glob handling; fixed exec <"$1"; added test and echo builtins
5
32007-06-13 62007-06-13
4hush: exec <"$1" doesn't do parameter subst 7hush: exec <"$1" doesn't do parameter subst
5 8
diff --git a/shell/hush.c b/shell/hush.c
index 04afbfd9a..912cbb5d9 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1361,8 +1361,11 @@ static int setup_redirects(struct child_prog *prog, int squirrel[])
1361 continue; 1361 continue;
1362 } 1362 }
1363 if (redir->dup == -1) { 1363 if (redir->dup == -1) {
1364 char *p;
1364 mode = redir_table[redir->type].mode; 1365 mode = redir_table[redir->type].mode;
1365 openfd = open_or_warn(redir->glob_word[0], mode); 1366 p = expand_string_to_string(redir->glob_word[0]);
1367 openfd = open_or_warn(p, mode);
1368 free(p);
1366 if (openfd < 0) { 1369 if (openfd < 0) {
1367 /* this could get lost if stderr has been redirected, but 1370 /* this could get lost if stderr has been redirected, but
1368 bash and ash both lose it as well (though zsh doesn't!) */ 1371 bash and ash both lose it as well (though zsh doesn't!) */
@@ -2579,7 +2582,7 @@ static int expand_vars_to_list(char **list, int n, char **posp, char *arg, char
2579 } 2582 }
2580 } else 2583 } else
2581 /* If or_mask is nonzero, we handle assignment 'a=....$@.....' 2584 /* If or_mask is nonzero, we handle assignment 'a=....$@.....'
2582 * and in this case should theat it like '$*' */ 2585 * and in this case should treat it like '$*' - see 'else...' below */
2583 if (first_ch == ('@'|0x80) && !or_mask) { /* quoted $@ */ 2586 if (first_ch == ('@'|0x80) && !or_mask) { /* quoted $@ */
2584 while (1) { 2587 while (1) {
2585 strcpy(pos, global_argv[i]); 2588 strcpy(pos, global_argv[i]);
@@ -2593,10 +2596,10 @@ static int expand_vars_to_list(char **list, int n, char **posp, char *arg, char
2593 list[n++] = pos; 2596 list[n++] = pos;
2594 } 2597 }
2595 } else { /* quoted $*: add as one word */ 2598 } else { /* quoted $*: add as one word */
2596 while (1) { 2599 if (global_argv[i]) while (1) {
2597 strcpy(pos, global_argv[i]); 2600 strcpy(pos, global_argv[i]);
2598 pos += strlen(global_argv[i]); 2601 pos += strlen(global_argv[i]);
2599 if (++i >= global_argc) 2602 if (!global_argv[++i])
2600 break; 2603 break;
2601 if (ifs[0]) 2604 if (ifs[0])
2602 *pos++ = ifs[0]; 2605 *pos++ = ifs[0];
diff --git a/shell/hush_test/hush-vars/var_expand_in_redir.right b/shell/hush_test/hush-vars/var_expand_in_redir.right
new file mode 100644
index 000000000..423299c97
--- /dev/null
+++ b/shell/hush_test/hush-vars/var_expand_in_redir.right
@@ -0,0 +1,3 @@
1TEST1
2TEST2
3TEST3
diff --git a/shell/hush_test/hush-vars/var_expand_in_redir.tests b/shell/hush_test/hush-vars/var_expand_in_redir.tests
new file mode 100755
index 000000000..bda6bdd7f
--- /dev/null
+++ b/shell/hush_test/hush-vars/var_expand_in_redir.tests
@@ -0,0 +1,13 @@
1if test $# = 0; then
2 exec "$THIS_SH" "$0" abc "d e"
3fi
4
5echo TEST1 >"$1.out"
6echo TEST2 >"$2.out"
7# bash says: "$@.out": ambiguous redirect
8# ash handles it as if it is '$*' - we do the same
9echo TEST3 >"$@.out"
10
11cat abc.out "d e.out" "abc d e.out"
12
13rm abc.out "d e.out" "abc d e.out"
diff --git a/shell/hush_test/run-all b/shell/hush_test/run-all
index 0d40ae6df..c75d81e55 100755
--- a/shell/hush_test/run-all
+++ b/shell/hush_test/run-all
@@ -11,6 +11,7 @@ export THIS_SH
11do_test() 11do_test()
12{ 12{
13 test -d "$1" || return 0 13 test -d "$1" || return 0
14# echo Running tests in directory "$1"
14 ( 15 (
15 cd "$1" || { echo "cannot cd $1!"; exit 1; } 16 cd "$1" || { echo "cannot cd $1!"; exit 1; }
16 for x in run-*; do 17 for x in run-*; do