ash: implement export -n
function old new delta exportcmd 129 175 +46 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
f47ce07b26
commit
d527588882
30
shell/ash.c
30
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user