[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 'declare' does not honor '-e' in command substituted assignments - a
Re: 'declare' does not honor '-e' in command substituted assignments - a bug ?
Sat, 09 Aug 2014 14:46:25 -0500
KMail/4.13.3 (Linux/3.16.0; KDE/4.13.3; x86_64; ; )
On Saturday, August 09, 2014 04:34:11 PM Jason Vas Dias wrote:
> Good day bash list -
> I don't understand why this emits any output :
> $ ( set -e; declare v=$(false); echo 'Should not get here'; )
> Should not get here
> While this does not:
> $ ( set -e; v=$(false); echo 'Should not get here'; )
"If there is no command name, but the command contained a command
substitution, the command shall complete with the exit status of the
command substitution performed. Otherwise, the command shall complete
a zero exit status."
The declaration commands return the status of the command itself, which masks
the status of assignments. To get the status, either perform the declaration
and assignment separately, or use a temporary variable to store the status. For
set -e the former is the only option.