On Fri, 2 Dec 2022 at 21:29, Ulrich Windl <ulrich.wi...@rz.uni-regensburg.de> wrote:
> Surprisingly "declare XXX=$(false);echo $?" outputs "0" (not "1") > There is no indication in the manual page that "declare" ignores > the exit code of commands being executed to set values. The above is not surprising at all. 'declare' is a builtin command. It succeeded. $ help declare | tail -n 3 Exit Status: Returns success unless an invalid option is supplied or a variable assignment error occurs. 'man bash' explains this comprehensively. The return value is 0 unless an invalid option is encountered, an attempt is made to define a function using ``-f foo=bar'', an attempt is made to assign a value to a readonly variable, an attempt is made to as‐ sign a value to an array variable without using the compound as‐ signment syntax (see Arrays above), one of the names is not a valid shell variable name, an attempt is made to turn off read‐ only status for a readonly variable, an attempt is made to turn off array status for an array variable, or an attempt is made to display a non-existent function with -f. Also, $(false) probably does not produce the value of $XXX that you expect. Try running 'echo $(false)'.