[Top][All Lists]

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

Re: Bash bug

From: Clark Wang
Subject: Re: Bash bug
Date: Tue, 23 Aug 2016 11:06:02 +0800

On Tue, Aug 23, 2016 at 2:34 AM, Weshakie Löwe <address@hidden> wrote:
When storing the value of code executed in a subshell the return value is always 0 if the variable is local.

Code example:

 local return_value="$(bash -c "exit 1")"
 echo $?

function A: returns 0 - even though obviously the return value is 1.

``local'' itself is a command. So ``local var=value'' would usually return 0 because it _successfully_ assigns the value the the var. ``local'' would return non-zero when there's something wrong with the syntax. For example ``local invalid.var.name'' or ``readonly var=1; local var=2''.

 return_value="$(bash -c "exit 1")"
 echo $?

function B: returns 1 - as expected, the only difference to function A being not using a local variable to store the value.

Without ``local'', the value of $? would be changed by the $(...) part in the assignment.


Best regards,

A happy bash user

reply via email to

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