0

I am running bash in Ipython notebook. I have a variable called run_state that presently is RUNNING. However when I try to compare its value to this string, it doesn't match. What am I doing wrong? The image shows the output of the first echo and that indeed run_state equals RUNNING

run_state="RUNNING"

gcloud ai-platform jobs describe $1 >describe
grep -m 1 -o 'state: [a-zA-Z]*'  describe | sed s/'state: '// >state
state_var=$(<state)

echo $state_var
if [ ["$state_var" == "$run_state"] ];
then
echo $state_var
fi

enter image description here

B_Miner
  • 1,840
  • 4
  • 31
  • 66
  • One of many terrible quirks with the various Unix/Linux shells. Related https://stackoverflow.com/questions/8934012/when-are-square-brackets-required-in-a-bash-if-statement – jarmod Jan 30 '20 at 03:02

1 Answers1

3

You can't have spaces between the brackets in [[, and you must have spaces around the brackets. So it should be

if [[ "$state_var" == "$run_state" ]];
Barmar
  • 741,623
  • 53
  • 500
  • 612