Add the SUSv3 -p ("portable") option to both the export and readonly
builtins. This makes export/readonly print lines in the form "export name=value".
This commit is contained in:
parent
86f99a57b2
commit
45086f8cf6
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=97914
22
bin/sh/sh.1
22
bin/sh/sh.1
@ -1406,7 +1406,11 @@ If
|
||||
is given
|
||||
it is used as the exit status of the shell;
|
||||
otherwise the exit status of the preceding command is used.
|
||||
.It Ic export Ar name ...
|
||||
.It Xo
|
||||
.Ic export
|
||||
.Op Fl p
|
||||
.Op Ar name ...
|
||||
.Xc
|
||||
The specified names are exported so that they will
|
||||
appear in the environment of subsequent commands.
|
||||
The only way to un-export a variable is to
|
||||
@ -1420,6 +1424,11 @@ export name=value
|
||||
.Pp
|
||||
With no arguments the export command lists the names
|
||||
of all exported variables.
|
||||
If the
|
||||
.Fl p
|
||||
option is specified, the exported variables are printed as
|
||||
.Dq Ic export Ar name Ns = Ns Ar value
|
||||
lines, suitable for re-input to the shell.
|
||||
.It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last
|
||||
.It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last
|
||||
.It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first
|
||||
@ -1662,7 +1671,11 @@ is assumed.
|
||||
The
|
||||
.Fl e
|
||||
option exists only for backward compatibility with older scripts.
|
||||
.It Ic readonly Ar name ...
|
||||
.It Xo
|
||||
.Ic readonly
|
||||
.Op Fl p
|
||||
.Op Ar name ...
|
||||
.Xc
|
||||
Each specified
|
||||
.Ar name
|
||||
is marked as read only,
|
||||
@ -1677,6 +1690,11 @@ readonly name=value
|
||||
With no arguments the
|
||||
.Ic readonly
|
||||
command lists the names of all read only variables.
|
||||
If the
|
||||
.Fl p
|
||||
option is specified, the read-only variables are printed as
|
||||
.Dq Ic readonly Ar name Ns = Ns Ar value
|
||||
lines, suitable for re-input to the shell.
|
||||
.It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo
|
||||
.Fl c Ar string Oc Op Fl - Ar arg ...
|
||||
The
|
||||
|
28
bin/sh/var.c
28
bin/sh/var.c
@ -531,10 +531,28 @@ exportcmd(int argc, char **argv)
|
||||
struct var *vp;
|
||||
char *name;
|
||||
char *p;
|
||||
char *cmdname;
|
||||
int ch, values;
|
||||
int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT;
|
||||
|
||||
cmdname = argv[0];
|
||||
optreset = optind = 1;
|
||||
values = 0;
|
||||
while ((ch = getopt(argc, argv, "p")) != -1) {
|
||||
switch (ch) {
|
||||
case 'p':
|
||||
values = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
error("unknown option: -%c", optopt);
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
listsetvar(cmdenviron);
|
||||
if (argc > 1) {
|
||||
if (argc != 0) {
|
||||
while ((name = *argptr++) != NULL) {
|
||||
if ((p = strchr(name, '=')) != NULL) {
|
||||
p++;
|
||||
@ -559,8 +577,16 @@ found:;
|
||||
for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
|
||||
for (vp = *vpp ; vp ; vp = vp->next) {
|
||||
if (vp->flags & flag) {
|
||||
if (values) {
|
||||
out1str(cmdname);
|
||||
out1c(' ');
|
||||
}
|
||||
for (p = vp->text ; *p != '=' ; p++)
|
||||
out1c(*p);
|
||||
if (values && !(vp->flags & VUNSET)) {
|
||||
out1c('=');
|
||||
out1qstr(p + 1);
|
||||
}
|
||||
out1c('\n');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user