I'm a beginner at Linux shell, but I know that this command creates a subshell:
Subshells are typically created using subshell operators or commands such as parentheses (), backticks `, or the $() syntax.
: ${FOO:=$([ "$BAR" = "baz" ] && echo "true" || echo "false" )}
This could be a problem e.g. in a loop (this is not the case here) but I like to learn how to avoid it. Generally speaking, in the above assignment, can a subshell be avoided using the following?
if [ -z "$FOO" ]; then
if [ "$BAR" = "baz" ]; then
FOO=true
else
FOO=false
fi
fi
true
andfalse
with$BASH_SUBSHELL
and check the output. – muru Jul 04 '23 at 11:18$(...)
creates a subshell, and you have one solution with it, and another without, and you want to know if the script that has nothing that would create a subshell runs without creating a subshell? (How much the subshell is a performance issue or not is an orthogonal matter, imo.) – ilkkachu Jul 04 '23 at 11:51