summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-06-06 03:57:22 +0000
committertjr <tjr@FreeBSD.org>2002-06-06 03:57:22 +0000
commitc74ee6d523a54949196b04673647cbd7ce5c4f01 (patch)
tree5a179ba5e57ce698955c4041f535870e6a841ea6 /bin
parent5e61aad926dd9d2ae6d8ad5070df268dcc0466fb (diff)
downloadFreeBSD-src-c74ee6d523a54949196b04673647cbd7ce5c4f01.zip
FreeBSD-src-c74ee6d523a54949196b04673647cbd7ce5c4f01.tar.gz
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".
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/sh.122
-rw-r--r--bin/sh/var.c28
2 files changed, 47 insertions, 3 deletions
diff --git a/bin/sh/sh.1 b/bin/sh/sh.1
index 57a21ee..34e4abe 100644
--- a/bin/sh/sh.1
+++ b/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
diff --git a/bin/sh/var.c b/bin/sh/var.c
index 42c240c..0af1eeb 100644
--- a/bin/sh/var.c
+++ b/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');
}
}
OpenPOWER on IntegriCloud