diff --git a/bin/sh/expand.c b/bin/sh/expand.c index be0f53ed051..832b51f12f5 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -460,7 +460,6 @@ expbackq(union node *cmd, int quoted, int flag, struct worddest *dst) p = grabstackstr(dest); evalbackcmd(cmd, &in); ungrabstackstr(p, dest); - argbackq = saveargbackq; p = in.buf; nnl = 0; @@ -514,12 +513,16 @@ expbackq(union node *cmd, int quoted, int flag, struct worddest *dst) close(in.fd); if (in.buf) ckfree(in.buf); - if (in.jp) + if (in.jp) { + p = grabstackstr(dest); exitstatus = waitforjob(in.jp, (int *)NULL); + ungrabstackstr(p, dest); + } TRACE(("expbackq: size=%td: \"%.*s\"\n", ((dest - stackblock()) - startloc), (int)((dest - stackblock()) - startloc), stackblock() + startloc)); + argbackq = saveargbackq; expdest = dest; INTON; } diff --git a/bin/sh/tests/expansion/Makefile b/bin/sh/tests/expansion/Makefile index 3c0dfa31923..c0622323517 100644 --- a/bin/sh/tests/expansion/Makefile +++ b/bin/sh/tests/expansion/Makefile @@ -42,6 +42,8 @@ ${PACKAGE}FILES+= cmdsubst17.0 ${PACKAGE}FILES+= cmdsubst18.0 ${PACKAGE}FILES+= cmdsubst19.0 ${PACKAGE}FILES+= cmdsubst20.0 +${PACKAGE}FILES+= cmdsubst21.0 +${PACKAGE}FILES+= cmdsubst22.0 ${PACKAGE}FILES+= export1.0 ${PACKAGE}FILES+= export2.0 ${PACKAGE}FILES+= export3.0 diff --git a/bin/sh/tests/expansion/cmdsubst21.0 b/bin/sh/tests/expansion/cmdsubst21.0 new file mode 100644 index 00000000000..87ff6a9db4a --- /dev/null +++ b/bin/sh/tests/expansion/cmdsubst21.0 @@ -0,0 +1,6 @@ +# $FreeBSD$ + +set -T +trapped='' +trap "trapped=x$trapped" TERM +[ "x$($SH -c "kill $$")y" = xy ] && [ "$trapped" = x ] diff --git a/bin/sh/tests/expansion/cmdsubst22.0 b/bin/sh/tests/expansion/cmdsubst22.0 new file mode 100644 index 00000000000..97c6c98dff8 --- /dev/null +++ b/bin/sh/tests/expansion/cmdsubst22.0 @@ -0,0 +1,6 @@ +# $FreeBSD$ + +set -T +trapped='' +trap "trapped=x$trapped" TERM +[ "x$(:; kill $$)y" = xy ] && [ "$trapped" = x ]