mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-23 03:06:48 +00:00
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:
parent
0b2e3aead3
commit
468ed39612
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=341164
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
11
bin/sh/tests/expansion/question2.0
Normal file
11
bin/sh/tests/expansion/question2.0
Normal 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
|
Loading…
Reference in a new issue