[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Doc on simple command expansion
From: |
Greg Wooledge |
Subject: |
Re: Doc on simple command expansion |
Date: |
Thu, 3 Mar 2022 09:27:44 -0500 |
On Thu, Mar 03, 2022 at 07:11:51PM +0800, Glen Huang wrote:
> Hi,
>
> I'm having difficulty understanding this paragraph from Bash Reference
> Manual Chapter 3.7.1.
>
> > If one of the expansions contained a command substitution, the exit status
> > of the command
> > is the exit status of the last command substitution performed. If there
> > were no command
> > substitutions, the command exits with a status of zero.
>
> Which seems to indicate that for a simple command like this
>
> echo "$(false)"
You took this quote out of context. From the man page, here's the whole
paragraph:
If there is a command name left after expansion, execution proceeds as
described below. Otherwise, the command exits. If one of the expanâ
sions contained a command substitution, the exit status of the command
is the exit status of the last command substitution performed. If
there were no command substitutions, the command exits with a status of
zero.
The piece that you quoted only applies in the "Otherwise" case, when
there is no command name after expansions. An example of this would
be:
unicorn:~$ q=$(false)
unicorn:~$ echo "$?"
1