diff options
author | Denis Vlasenko | 2009-03-20 12:05:14 +0000 |
---|---|---|
committer | Denis Vlasenko | 2009-03-20 12:05:14 +0000 |
commit | a8b6dff97f353c41e208e7e567f100a6c7af4605 (patch) | |
tree | 6a6722ac176e2f04261bf29202e87767c3d9349e /shell/hush.c | |
parent | 5368ad53e91ee056316389b5006b7eb0df2f2d11 (diff) | |
download | busybox-a8b6dff97f353c41e208e7e567f100a6c7af4605.zip busybox-a8b6dff97f353c41e208e7e567f100a6c7af4605.tar.gz |
hush: fix bug 207 and "hush -c" parameter passing.
Now hush -c 'printf "%s\n" "$@"' (prints "\n")
and hush -c 'printf "%s\n" "$@"' qwe asd (prints "asd\n")
both work correctly
Diffstat (limited to 'shell/hush.c')
-rw-r--r-- | shell/hush.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/shell/hush.c b/shell/hush.c index e6189f8..bfd487c 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -1219,8 +1219,13 @@ static int o_glob(o_string *o, int n) * Otherwise, just finish current list[] and start new */ static int o_save_ptr(o_string *o, int n) { - if (o->o_glob) - return o_glob(o, n); /* o_save_ptr_helper is inside */ + if (o->o_glob) { /* if globbing is requested */ + /* If o->has_empty_slot, list[n] was already globbed + * (if it was requested back then when it was filled) + * so don't do that again! */ + if (!o->has_empty_slot) + return o_glob(o, n); /* o_save_ptr_helper is inside */ + } return o_save_ptr_helper(o, n); } @@ -4285,6 +4290,11 @@ int hush_main(int argc, char **argv) switch (opt) { case 'c': G.global_argv = argv + optind; + if (!argv[optind]) { + /* -c 'script' (no params): prevent empty $0 */ + *--G.global_argv = argv[0]; + optind--; + } /* else -c 'script' PAR0 PAR1: $0 is PAR0 */ G.global_argc = argc - optind; opt = parse_and_run_string(optarg, 0 /* parse_flag */); goto final_return; |