diff options
Diffstat (limited to 'shell')
-rw-r--r-- | shell/hush.c | 42 | ||||
-rw-r--r-- | shell/hush_test/hush-vars/unset.right | 5 |
2 files changed, 18 insertions, 29 deletions
diff --git a/shell/hush.c b/shell/hush.c index 292b8b2e3..d0819f691 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -6451,7 +6451,11 @@ static int builtin_export(char **argv) } #if ENABLE_HUSH_EXPORT_N - opt_unexport = getopt32(argv, "+n"); /* "+": stop at 1st non-option */ + /* "!": do not abort on errors */ + /* "+": stop at 1st non-option */ + opt_unexport = getopt32(argv, "!+n"); + if (opt_unexport == (unsigned)-1) + return EXIT_FAILURE; argv += optind; #else opt_unexport = 0; @@ -6918,36 +6922,22 @@ static int builtin_umask(char **argv) static int builtin_unset(char **argv) { int ret; - char var; - char *arg; - - if (!*++argv) - return EXIT_SUCCESS; + unsigned opts; - var = 0; - while ((arg = *argv) != NULL && arg[0] == '-') { - arg++; - do { - switch (*arg) { - case 'v': - case 'f': - if (var == 0 || var == *arg) { - var = *arg; - break; - } - /* else: unset -vf, which is illegal. - * fall through */ - default: - bb_error_msg("unset: %s: invalid option", *argv); - return EXIT_FAILURE; - } - } while (*++arg); - argv++; + /* "!": do not abort on errors */ + /* "+": stop at 1st non-option */ + opts = getopt32(argv, "!+vf"); + if (opts == (unsigned)-1) + return EXIT_FAILURE; + if (opts == 3) { + bb_error_msg("unset: -v and -f are exclusive"); + return EXIT_FAILURE; } + argv += optind; ret = EXIT_SUCCESS; while (*argv) { - if (var != 'f') { + if (!(opts & 2)) { /* not -f */ if (unset_local_var(*argv)) { /* unset <nonexistent_var> doesn't fail. * Error is when one tries to unset RO var. diff --git a/shell/hush_test/hush-vars/unset.right b/shell/hush_test/hush-vars/unset.right index 8dea7c40d..1fbe76a73 100644 --- a/shell/hush_test/hush-vars/unset.right +++ b/shell/hush_test/hush-vars/unset.right @@ -1,6 +1,5 @@ -hush: unset: -: invalid option -1 -hush: unset: -m: invalid option +0 +unset: invalid option -- m 1 0 ___ |