On 12/02/2022 at 12:23, David Hobach wrote:
function tfunc {
local foo=
foo="$(testCode)" || {echo "foo";}
^ Missing space after opening brace
Because the code block is missing a space after the opening brace; the
opening brace is ignored, but the following closing brace is parsed as
the end for the tfunc function code block.
The following statements are executed for the global scope since the
function definition block is closed by the faulty syntax above.
cat "$foo" || {
badCode
case $? in
*)
exit 1
esac
}
}
The bug is in your code.
https://shellcheck.net/ static analysis for shell scripts can help you
spot such syntax errors.
--
Léa Gris