summaryrefslogtreecommitdiffstats
path: root/bin/sh/var.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2011-06-12 23:06:04 +0000
committerjilles <jilles@FreeBSD.org>2011-06-12 23:06:04 +0000
commit91789615b49a87147298eee12c9b111d8c1b64c9 (patch)
treeb1cbd950b159dbb3fa6211ba5a7f7fb7709a612e /bin/sh/var.c
parent5f2600c6a978923a3904716ce73814baca63fd0f (diff)
downloadFreeBSD-src-91789615b49a87147298eee12c9b111d8c1b64c9.zip
FreeBSD-src-91789615b49a87147298eee12c9b111d8c1b64c9.tar.gz
sh: Save/restore changed variables in optimized command substitution.
In optimized command substitution, save and restore any variables changed by expansions (${var=value} and $((var=assigned))), instead of trying to determine if an expansion may cause such changes. If $! is referenced in optimized command substitution, do not cause jobs to be remembered longer. This fixes $(jobs $!) again, simplifies the man page and shortens the code.
Diffstat (limited to 'bin/sh/var.c')
-rw-r--r--bin/sh/var.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/bin/sh/var.c b/bin/sh/var.c
index f6d7fb1..e405b66 100644
--- a/bin/sh/var.c
+++ b/bin/sh/var.c
@@ -94,6 +94,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 +327,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)
@@ -740,9 +744,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 +755,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