I am evaluating following following expression. And it always evaluates to true even if CMD is START or STARTED. Am I doing something wrong?
if [ "$CMD"="START" ]; then
echo fi
fi
I am evaluating following following expression. And it always evaluates to true even if CMD is START or STARTED. Am I doing something wrong?
if [ "$CMD"="START" ]; then
echo fi
fi
Try spaces
if [ "$CMD" = "START" ] ; then
echo fi
fi
[ ] turned into [[ ]] to make sure it's evaluated by bash itself :)$CMD.grep -i "CMD" $TPMSTATUS | cut -d":" -f2 where TPMSTATUS contains the string CMD and its value separated by :echo "x$CMDx" to see if you're getting spaces or something before or after.You need to have spaces around the =.
#CMD="STARTED"
#if [ "$CMD" = "START" ] ; then echo fi; fi
#CMD="START"
#if [ "$CMD" = "START" ] ; then echo fi; fi
fi
#
From http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html:
[] vs. [[]]Contrary to [, [[ prevents word splitting of variable values. So, if VAR="var with spaces", you do not need to double quote $VAR in a test - eventhough using quotes remains a good habit. Also, [[ prevents pathname expansion, so literal strings with wildcards do not try to expand to filenames. Using [[, == and != interpret strings to the right as shell glob patterns to be matched against the value to the left, for instance: [[ "value" == val* ]].
So, try:
if [[ "$CMD" == "START" ]]; then
echo "fi"
fi