I'm confused by this output:
$ readonly foo=`exit 1`
$ echo $?
0
$ bar=`exit 1`
$ echo $?
1
Why does the readonly
make a difference?
readonly
is a function call and is entered after the exit 1
subshell has finished.
Your script now returns the return value of readonly
.
A one-liner that retains the return code semantics could be
foo=`exit 1` ; RC=$? ; readonly foo ; `exit $RC`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With