0

I am very confused as to why this while loop does not terminate, even though stack_status looks like it is equal to CREATE_COMPLETE. Did I forget something trivial?

stack_status=""
while [[ $stack_status != "CREATE_COMPLETE" ]]; 
do
   stack_status=$(aws cloudformation --region us-east-2 describe-stacks --stack-name ${stack_name} --query Stacks[0].StackStatus);   
   echo "Waiting for stack to complete"; 
   echo $stack_status;   
   sleep 5; 
done

Output

Waiting for stack to complete
"CREATE_COMPLETE"
Waiting for stack to complete
"CREATE_COMPLETE"
Waiting for stack to complete
"CREATE_COMPLETE"
Waiting for stack to complete
"CREATE_COMPLETE"
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Timothy Pulliam
  • 132
  • 1
  • 9
  • 25
  • 2
    Your string is `"CREATE_COMPLETE"`, not `CREATE_COMPLETE`; they don't match. – Charles Duffy Nov 08 '21 at 20:51
  • 1
    Also, `echo $stack_status` is itself buggy; see [I just assigned a variable, but `echo $variable` shows something else](https://stackoverflow.com/questions/29378566/i-just-assigned-a-variable-but-echo-variable-shows-something-else) – Charles Duffy Nov 08 '21 at 20:52
  • 1
    (Consider running your code through http://shellcheck.net/; it'll automatically identify quoting errors, among others). – Charles Duffy Nov 08 '21 at 20:54
  • @CharlesDuffy I will be using shellcheck.net from now on for sure. Thanks for that. – Timothy Pulliam Nov 08 '21 at 21:06

1 Answers1

3

If you want the double quotes to be considered literal data, put single quotes around them.

while [[ $stack_status != '"CREATE_COMPLETE"' ]]; do
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441