aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-10-01 13:41:17 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2012-10-01 13:41:17 +0200
commitd5275888821a8382e7a493d90cebb7b23d975795 (patch)
treeaa1d7897a67090ad6984b82edf512d6ac5e8df91 /shell
parentf47ce07b2699134d94dae9320dabc4a91c3c6b83 (diff)
downloadbusybox-d5275888821a8382e7a493d90cebb7b23d975795.tar.gz
ash: implement export -n
function old new delta exportcmd 129 175 +46 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c30
1 files changed, 26 insertions, 4 deletions
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;
+
+ /* "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 (nextopt("p") != 'p') {
+ /*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;
}