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
This commit is contained in:
Jilles Tjoelker 2018-11-28 20:03:53 +00:00
parent 0b2e3aead3
commit 468ed39612
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=341164
3 changed files with 15 additions and 2 deletions

View file

@ -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) {

View file

@ -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

View file

@ -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