I am comparing strings between a variable and a constant. The result of the comparison is either true or false assigned to another variable.
true
false
LABEL=$("${INPUT}" == "flag");
However, I fail. Any suggestion?
You can use expr :
expr
INPUT='flag' LABEL=$(expr "${INPUT}" == "flag") echo "$LABEL" 1 INPUT='flab' LABEL=$(expr "${INPUT}" == "flag") echo "$LABEL" 0
This is probably simpler and may cover more test cases. You can get more detailed information about string comparisons and test cases using the "man test". Here is a pretty simple example.
if [ "${INPUT}" == "flag" ]; then LABEL=${INPUT} fi echo ${LABEL}