[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Return status of command substitution with $(...) "gets lost"

From: Marc Herbert
Subject: Re: Return status of command substitution with $(...) "gets lost"
Date: Thu, 11 Mar 2010 16:27:28 +0000
User-agent: Thunderbird (X11/20090825)

Chet Ramey wrote:

> To Posix, assignment statements never fail -- assignment errors cause
> non- interactive shells to exit, period.  In that case, it's possible
> to reflect the exit status of a command substitution in the exit
> status of a command consisting only of assignment statements,...

It's possible... and required by POSIX, right? 

At least this is my understanding of section "2.9.1 Simple Commands".
More precisely: "... with the exit status of the LAST command
substitution performed"

Just to make things less abstract, here is some (simplified) code I
often find useful:

local _res
if _res=$( some_code... ); then
   echo $_res
elif _res=$( some_other_code... );
   echo $_res
   return 1

> ... though that has problems of its own and is only reliable on commands
> consisting of a single assignment.

Here you seem to imply this is actually an "advanced" and thus
non-standard feature (why I have no clue). An unreliable feature would
never have been standardized for sure...

reply via email to

[Prev in Thread] Current Thread [Next in Thread]