svn commit: r341164 - in head/bin/sh: . tests/expansion
Jilles Tjoelker
jilles at FreeBSD.org
Wed Nov 28 20:03:54 UTC 2018
Author: jilles
Date: Wed Nov 28 20:03:53 2018
New Revision: 341164
URL: https://svnweb.freebsd.org/changeset/base/341164
Log:
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
Added:
head/bin/sh/tests/expansion/question2.0 (contents, props changed)
Modified:
head/bin/sh/expand.c
head/bin/sh/tests/expansion/Makefile
Modified: head/bin/sh/expand.c
==============================================================================
--- head/bin/sh/expand.c Wed Nov 28 19:54:02 2018 (r341163)
+++ head/bin/sh/expand.c Wed Nov 28 20:03:53 2018 (r341164)
@@ -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 **restr
setvar(var, startp, 0);
amount = startp - expdest;
STADJUST(amount, expdest);
- return p;
+ return end;
case VSQUESTION:
if (*p != CTLENDVAR) {
Modified: head/bin/sh/tests/expansion/Makefile
==============================================================================
--- head/bin/sh/tests/expansion/Makefile Wed Nov 28 19:54:02 2018 (r341163)
+++ head/bin/sh/tests/expansion/Makefile Wed Nov 28 20:03:53 2018 (r341164)
@@ -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
Added: head/bin/sh/tests/expansion/question2.0
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/bin/sh/tests/expansion/question2.0 Wed Nov 28 20:03:53 2018 (r341164)
@@ -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
More information about the svn-src-all
mailing list