summaryrefslogtreecommitdiffstats
path: root/bin/sh/var.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sh/var.c')
-rw-r--r--bin/sh/var.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/bin/sh/var.c b/bin/sh/var.c
index f6d7fb1..b3bc6f7f 100644
--- a/bin/sh/var.c
+++ b/bin/sh/var.c
@@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$");
#include "error.h"
#include "mystring.h"
#include "parser.h"
+#include "builtins.h"
#ifndef NO_HISTORY
#include "myhistedit.h"
#endif
@@ -94,6 +95,8 @@ struct var vps4;
struct var vvers;
static struct var voptind;
+int forcelocal;
+
static const struct varinit varinit[] = {
#ifndef NO_HISTORY
{ &vhistsize, VUNSET, "HISTSIZE=",
@@ -325,6 +328,8 @@ setvareq(char *s, int flags)
if (aflag)
flags |= VEXPORT;
+ if (forcelocal && !(flags & (VNOSET | VNOLOCAL)))
+ mklocal(s);
vp = find_var(s, &vpp, &nlen);
if (vp != NULL) {
if (vp->flags & VREADONLY)
@@ -607,6 +612,12 @@ showvarscmd(int argc __unused, char **argv __unused)
qsort(vars, n, sizeof(*vars), var_compare);
for (i = 0; i < n; i++) {
+ /*
+ * Skip improper variable names so the output remains usable as
+ * shell input.
+ */
+ if (!isassignment(vars[i]))
+ continue;
s = strchr(vars[i], '=');
s++;
outbin(vars[i], s - vars[i], out1);
@@ -678,6 +689,13 @@ exportcmd(int argc, char **argv)
for (vp = *vpp ; vp ; vp = vp->next) {
if (vp->flags & flag) {
if (values) {
+ /*
+ * Skip improper variable names
+ * so the output remains usable
+ * as shell input.
+ */
+ if (!isassignment(vp->text))
+ continue;
out1str(cmdname);
out1c(' ');
}
@@ -740,9 +758,9 @@ mklocal(char *name)
vp = find_var(name, &vpp, NULL);
if (vp == NULL) {
if (strchr(name, '='))
- setvareq(savestr(name), VSTRFIXED);
+ setvareq(savestr(name), VSTRFIXED | VNOLOCAL);
else
- setvar(name, NULL, VSTRFIXED);
+ setvar(name, NULL, VSTRFIXED | VNOLOCAL);
vp = *vpp; /* the new variable */
lvp->text = NULL;
lvp->flags = VUNSET;
@@ -751,7 +769,7 @@ mklocal(char *name)
lvp->flags = vp->flags;
vp->flags |= VSTRFIXED|VTEXTFIXED;
if (name[vp->name_len] == '=')
- setvareq(savestr(name), 0);
+ setvareq(savestr(name), VNOLOCAL);
}
}
lvp->vp = vp;
OpenPOWER on IntegriCloud