Re: :? within a function

Zachary Santer <[email protected]> Sun, 17 May 2026 21:47:54 -0400
Newsgroups gmane.comp.shells.bash.help,gmane.comp.shells.bash.bugs
Message-ID <CABkLJULG46pLTkP6_u3U+UbD=Vv++D0dJYT9zTe4+UY0JJNPPQ@mail.gmail.com>
On Fri, Apr 24, 2026 at 10:56 AM Greg Wooledge <[email protected]> wrote:
>
> On Fri, Apr 24, 2026 at 08:07:36 -0600, Stan Marsh wrote:
> >
> > Although not incorrect, it looks like it could use some more words...
>
> So you already knew this before you asked.  What are you confused
> about?  What additional words do you think are needed?

On Fri, Apr 24, 2026 at 10:08 AM Stan Marsh <gazelle-aS9lmoZGLiVWk0Htik3J/[email protected]> wrote:
>
> But what about in an interactive shell (as when we source it)?  In
> that case, I've noticed that while the shell itself does not exit (which is a Good
> Thing!), the function (fiz) does exit (that is, the "OK" is not output).
>
> As far as I can tell, the fact that the function enclosing the :? exits, even in an
> interactive shell, is not documented.

The current devel branch (commit 669b32f676) manual says this:
${parameter:?word}
Display Error if Null or Unset. If parameter is unset or null, or
unset if the colon is not present, the shell writes the expansion of
word (or a message to that effect if word is not present) to the
standard error and, if it is not interactive, exits with a non-zero
status. An interactive shell does not exit, but does not execute the
command associated with the expansion. Otherwise, the value of
parameter is substituted.

$ f1 () { f2; printf '%s\n' "f1 () continues" "f2 () exited with ${?}
exit code"; }
$ f2 () { ${1:?}; printf '%s\n' "f2 () continues"; }
$ f1
bash: 1: parameter null or not set
$ printf '%s\n' "${?}"
1
$ f2
bash: 1: parameter null or not set
$ printf '%s\n' "${?}"
1

So maybe the manual could be updated to
${parameter:?word}
Display Error if Null or Unset. If parameter is unset or null, or
unset if the colon is not present, the shell writes the expansion of
word (or a message to that effect if word is not present) to the
standard error and, if it is not interactive, exits with a non-zero
status. An interactive shell does not exit, but does not execute the
command associated with the expansion and any containing function
calls exit with a nonzero status. Otherwise, the value of parameter is
substituted.

Stan, I know you proposed discussing documentation flaws in help-bash,
but I'm not sure how much attention Chet pays to that list.