I have an expression like this:
if [[ $s == *Mar* ]]; then "match"; else "not"; fi;
How do assign its value to a variable?
command substitution syntax does not work, because bash tries to evaluate the result of the expression:
x=$(if [[ $s == *Mar* ]]; then "match"; else "not"; fi;)
gives the error:
-bash: match: command not found
So, basically I want to tell bash to evaluate an expression, but do not treat the output as a command.
How do I do that?
is not an expression; it is a command. You could make it into a command that outputs either
matchornotby inserting appropriateechocommands, and then capture the output with backticks or$().But that would be pointlessly indirect. Why not simply
?