Bug 233585 - sh(1) ${param?} default error message is broken
Summary: sh(1) ${param?} default error message is broken
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 12.0-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: Jilles Tjoelker
URL:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2018-11-27 22:30 UTC by Jilles Tjoelker
Modified: 2019-07-08 21:47 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jilles Tjoelker freebsd_committer 2018-11-27 22:30:49 UTC
*background*

The expansion ${param?word} is like ${param} but causes the shell to abort when param is not set. The word is expanded and written as an error message; if it is omitted (${param?}), a default error message is written.

*steps to reproduce*

sh -c 'unset something; ${something?}'

*expected results*

Output containing "something: parameter not set" and non-zero exit status.

*actual results*

Output of an empty line and non-zero exit status.

*notes*

This is a regression caused by SVN r316417. It affects stable/12 but not stable/11.

If the ${something?} is nested within another expansion, like ${other-${something?}}, the default error message does appear but is corrupted ("sh: something=: parameter not set").

The shell does exit or not exit when it should; this bug probably only makes debugging harder.
Comment 1 commit-hook freebsd_committer 2018-11-28 20:04:03 UTC
A commit references this bug:

Author: jilles
Date: Wed Nov 28 20:03:54 UTC 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

Changes:
  head/bin/sh/expand.c
  head/bin/sh/tests/expansion/Makefile
  head/bin/sh/tests/expansion/question2.0
Comment 2 commit-hook freebsd_committer 2018-12-09 19:14:35 UTC
A commit references this bug:

Author: jilles
Date: Sun Dec  9 19:14:22 UTC 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

Changes:
_U  stable/12/
  stable/12/bin/sh/expand.c
  stable/12/bin/sh/tests/expansion/Makefile
  stable/12/bin/sh/tests/expansion/question2.0