diff --git a/shell/ash.c b/shell/ash.c index d42316a88..010924db4 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -12630,9 +12630,27 @@ exportcmd(int argc UNUSED_PARAM, char **argv) char *name; const char *p; char **aptr; - int flag = argv[0][0] == 'r' ? VREADONLY : VEXPORT; + char opt; + int flag; + int flag_off; - if (nextopt("p") != 'p') { + /* "readonly" in bash accepts, but ignores -n. + * We do the same: it saves a conditional in nextopt's param. + */ + flag_off = 0; + while ((opt = nextopt("np")) != '\0') { + if (opt == 'n') + flag_off = VEXPORT; + } + flag = VEXPORT; + if (argv[0][0] == 'r') { + flag = VREADONLY; + flag_off = 0; /* readonly ignores -n */ + } + flag_off = ~flag_off; + + /*if (opt_p_not_specified) - bash doesnt check this. Try "export -p NAME" */ + { aptr = argptr; name = *aptr; if (name) { @@ -12643,15 +12661,19 @@ exportcmd(int argc UNUSED_PARAM, char **argv) } else { vp = *findvar(hashvar(name), name); if (vp) { - vp->flags |= flag; + vp->flags = ((vp->flags | flag) & flag_off); continue; } } - setvar(name, p, flag); + setvar(name, p, (flag & flag_off)); } while ((name = *++aptr) != NULL); return 0; } } + + /* No arguments. Show the list of exported or readonly vars. + * -n is ignored. + */ showvars(argv[0], flag, 0); return 0; }