summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2013-01-13 19:19:40 +0000
committerjilles <jilles@FreeBSD.org>2013-01-13 19:19:40 +0000
commit1af5c5cc5f617aaef7ab78705c5c70caea880cb1 (patch)
tree69e38a953148ba5a234ec291b11123361e88e213
parent247875210d7ec5d2e7810928c3c2fcfcbd68aa39 (diff)
downloadFreeBSD-src-1af5c5cc5f617aaef7ab78705c5c70caea880cb1.zip
FreeBSD-src-1af5c5cc5f617aaef7ab78705c5c70caea880cb1.tar.gz
sh: Don't lose $? when backquoted command ends with semicolon or newline.
An empty simple command was added and overwrote the exit status with 0. This affects `...` but not $(...). Example: v=`false;`; echo $?
-rw-r--r--bin/sh/parser.c3
-rw-r--r--tools/regression/bin/sh/expansion/cmdsubst14.05
-rw-r--r--tools/regression/bin/sh/expansion/cmdsubst15.05
3 files changed, 12 insertions, 1 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index ef1aa36..a19ca31 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -286,7 +286,8 @@ list(int nlflag, int erflag)
tokpushback++;
}
checkkwd = CHKNL | CHKKWD | CHKALIAS;
- if (!nlflag && !erflag && tokendlist[peektoken()])
+ if (!nlflag && (erflag ? peektoken() == TEOF :
+ tokendlist[peektoken()]))
return ntop;
break;
case TEOF:
diff --git a/tools/regression/bin/sh/expansion/cmdsubst14.0 b/tools/regression/bin/sh/expansion/cmdsubst14.0
new file mode 100644
index 0000000..bdbbb82
--- /dev/null
+++ b/tools/regression/bin/sh/expansion/cmdsubst14.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+! v=`false
+
+`
diff --git a/tools/regression/bin/sh/expansion/cmdsubst15.0 b/tools/regression/bin/sh/expansion/cmdsubst15.0
new file mode 100644
index 0000000..31d85d4
--- /dev/null
+++ b/tools/regression/bin/sh/expansion/cmdsubst15.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+! v=`false;
+
+`
OpenPOWER on IntegriCloud