diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-20 12:05:14 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-20 12:05:14 +0000 |
commit | a8b6dff97f353c41e208e7e567f100a6c7af4605 (patch) | |
tree | 6a6722ac176e2f04261bf29202e87767c3d9349e /shell/hush.c | |
parent | 5368ad53e91ee056316389b5006b7eb0df2f2d11 (diff) | |
download | busybox-w32-a8b6dff97f353c41e208e7e567f100a6c7af4605.tar.gz busybox-w32-a8b6dff97f353c41e208e7e567f100a6c7af4605.tar.bz2 busybox-w32-a8b6dff97f353c41e208e7e567f100a6c7af4605.zip |
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 e6189f841..bfd487cfb 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -1219,8 +1219,13 @@ static int o_glob(o_string *o, int n) | |||
1219 | * Otherwise, just finish current list[] and start new */ | 1219 | * Otherwise, just finish current list[] and start new */ |
1220 | static int o_save_ptr(o_string *o, int n) | 1220 | static int o_save_ptr(o_string *o, int n) |
1221 | { | 1221 | { |
1222 | if (o->o_glob) | 1222 | if (o->o_glob) { /* if globbing is requested */ |
1223 | return o_glob(o, n); /* o_save_ptr_helper is inside */ | 1223 | /* If o->has_empty_slot, list[n] was already globbed |
1224 | * (if it was requested back then when it was filled) | ||
1225 | * so don't do that again! */ | ||
1226 | if (!o->has_empty_slot) | ||
1227 | return o_glob(o, n); /* o_save_ptr_helper is inside */ | ||
1228 | } | ||
1224 | return o_save_ptr_helper(o, n); | 1229 | return o_save_ptr_helper(o, n); |
1225 | } | 1230 | } |
1226 | 1231 | ||
@@ -4285,6 +4290,11 @@ int hush_main(int argc, char **argv) | |||
4285 | switch (opt) { | 4290 | switch (opt) { |
4286 | case 'c': | 4291 | case 'c': |
4287 | G.global_argv = argv + optind; | 4292 | G.global_argv = argv + optind; |
4293 | if (!argv[optind]) { | ||
4294 | /* -c 'script' (no params): prevent empty $0 */ | ||
4295 | *--G.global_argv = argv[0]; | ||
4296 | optind--; | ||
4297 | } /* else -c 'script' PAR0 PAR1: $0 is PAR0 */ | ||
4288 | G.global_argc = argc - optind; | 4298 | G.global_argc = argc - optind; |
4289 | opt = parse_and_run_string(optarg, 0 /* parse_flag */); | 4299 | opt = parse_and_run_string(optarg, 0 /* parse_flag */); |
4290 | goto final_return; | 4300 | goto final_return; |