【问题标题】:String comparison in [[ ]] failing when target string contains quotes当目标字符串包含引号时 [[ ]] 中的字符串比较失败
【发布时间】:2021-12-21 15:59:12
【问题描述】:

我很困惑为什么这个while循环没有终止,即使stack_status看起来等于CREATE_COMPLETE。我是不是忘记了一些琐碎的事情?

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

输出

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"

【问题讨论】:

标签: bash while-loop


【解决方案1】:

如果您希望将双引号视为文字数据,请在它们周围加上单引号。

while [[ $stack_status != '"CREATE_COMPLETE"' ]]; do

【讨论】:

  • 天哪,就是这样。
  • 我得等几分钟才能到,所以现在不会让我这样做。
猜你喜欢
  • 1970-01-01
  • 2023-03-11
  • 2012-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-16
相关资源
最近更新 更多