aboutsummaryrefslogtreecommitdiff
path: root/bin/sh
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2018-11-28 20:03:53 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2018-11-28 20:03:53 +0000
commit468ed396127c15aab12c944f335518f63ae9569c (patch)
treed94c620c44aae4e41238283c6262b9c66d1701a4 /bin/sh
parent0b2e3aead3e6db5027c8a437922185d8a7b5235a (diff)
downloadsrc-468ed396127c15aab12c944f335518f63ae9569c.tar.gz
src-468ed396127c15aab12c944f335518f63ae9569c.zip
sh: Fix ${param?} default error message
If word in ${param?word} is missing, the shell shall write a default error message. So expanding ${param?} when param is not set should write an error message like sh: param: parameter not set This was broken by r316417. PR: 233585
Notes
Notes: svn path=/head/; revision=341164
Diffstat (limited to 'bin/sh')
-rw-r--r--bin/sh/expand.c5
-rw-r--r--bin/sh/tests/expansion/Makefile1
-rw-r--r--bin/sh/tests/expansion/question2.011
3 files changed, 15 insertions, 2 deletions
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index 6316400c88d5..922bf5c3c4e8 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -623,10 +623,11 @@ static const char *
subevalvar_misc(const char *p, struct nodelist **restrict argbackq,
const char *var, int subtype, int startloc, int varflags)
{
+ const char *end;
char *startp;
int amount;
- p = argstr(p, argbackq, EXP_TILDE, NULL);
+ end = argstr(p, argbackq, EXP_TILDE, NULL);
STACKSTRNUL(expdest);
startp = stackblock() + startloc;
@@ -635,7 +636,7 @@ subevalvar_misc(const char *p, struct nodelist **restrict argbackq,
setvar(var, startp, 0);
amount = startp - expdest;
STADJUST(amount, expdest);
- return p;
+ return end;
case VSQUESTION:
if (*p != CTLENDVAR) {
diff --git a/bin/sh/tests/expansion/Makefile b/bin/sh/tests/expansion/Makefile
index e087df723652..4f344c4a5161 100644
--- a/bin/sh/tests/expansion/Makefile
+++ b/bin/sh/tests/expansion/Makefile
@@ -86,6 +86,7 @@ ${PACKAGE}FILES+= plus-minus7.0
${PACKAGE}FILES+= plus-minus8.0
${PACKAGE}FILES+= plus-minus9.0
${PACKAGE}FILES+= question1.0
+${PACKAGE}FILES+= question2.0
${PACKAGE}FILES+= readonly1.0
${PACKAGE}FILES+= redir1.0
${PACKAGE}FILES+= set-u1.0
diff --git a/bin/sh/tests/expansion/question2.0 b/bin/sh/tests/expansion/question2.0
new file mode 100644
index 000000000000..592385d1df02
--- /dev/null
+++ b/bin/sh/tests/expansion/question2.0
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+unset dummyvar
+msg=`(: ${dummyvar?}) 2>&1`
+r=$?
+[ "$r" != 0 ] && case $msg in
+*dummyvar?* | *?dummyvar*) : ;;
+*)
+ printf 'Bad message: [%s]\n' "$msg"
+ exit 1
+esac