Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 9 Dec 2018 19:14:21 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r341767 - in stable/12/bin/sh: . tests/expansion
Message-ID:  <201812091914.wB9JELTI053534@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sun Dec  9 19:14:21 2018
New Revision: 341767
URL: https://svnweb.freebsd.org/changeset/base/341767

Log:
  MFC r341164: 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:
  stable/12/bin/sh/tests/expansion/question2.0
     - copied unchanged from r341164, head/bin/sh/tests/expansion/question2.0
Modified:
  stable/12/bin/sh/expand.c
  stable/12/bin/sh/tests/expansion/Makefile
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/bin/sh/expand.c
==============================================================================
--- stable/12/bin/sh/expand.c	Sun Dec  9 17:55:10 2018	(r341766)
+++ stable/12/bin/sh/expand.c	Sun Dec  9 19:14:21 2018	(r341767)
@@ -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: stable/12/bin/sh/tests/expansion/Makefile
==============================================================================
--- stable/12/bin/sh/tests/expansion/Makefile	Sun Dec  9 17:55:10 2018	(r341766)
+++ stable/12/bin/sh/tests/expansion/Makefile	Sun Dec  9 19:14:21 2018	(r341767)
@@ -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

Copied: stable/12/bin/sh/tests/expansion/question2.0 (from r341164, head/bin/sh/tests/expansion/question2.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/bin/sh/tests/expansion/question2.0	Sun Dec  9 19:14:21 2018	(r341767, copy of r341164, head/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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201812091914.wB9JELTI053534>