[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] confused by command substitution...
From: |
Chet Ramey |
Subject: |
Re: [Help-bash] confused by command substitution... |
Date: |
Mon, 11 Feb 2019 11:37:35 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 |
On 2/9/19 1:12 PM, Andy Chu wrote:
> This doesn't have to do with command subs, or even if statements. The way
> I think of it is that a command line can evaluate to an empty argv array
> after splitting ("elision"), and then that empty argv array silently
> *succeeds*.
Or, as POSIX puts it when describing the results of word expansion on
simple commands:
"If there is no command name, but the command contained a command
substitution, the command shall complete with the exit status of the last
command substitution performed. Otherwise, the command shall complete with
a zero exit status."
So the command list following the if statement in both
if $(echo x >/dev/null); then echo ok; fi
and
if $(exit 42); then echo ok; fi
is a simple command, and both result in empty word lists after expansion,
but only the first one has a zero exit status.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU address@hidden http://tiswww.cwru.edu/~chet/