我创建了这个bash脚本,似乎无法弄清楚为什么if块中的代码没有执行。
db_instances_status="creating"
db_instances_status=$(makes api request to get value)
COUNTER=0
while [ $COUNTER -lt 1 ]; do
db_instances_status=$(makes api request to get value)
echo "$db_instances_status" # echos available
if [ "available" = "$db_instances_status" ]; then
# code never makes it here
dosomething()
break;
fi
sleep 30
done
我遵循了How to compare strings in Bash
中的示例此处https://tecadmin.net/tutorial/bash/examples/check-if-two-strings-are-equal/
答案 0 :(得分:1)
您要么没有进入if
语句,要么变量不包含您认为的内容。
此代码段将帮助调试两个...
while [ $COUNTER -lt 1 ]; do
echo "[DEBUG] getting status"
db_instances_status=$(makes api request to get value)
echo "[DEBUG] X${db_instances_status}X"
echo "$db_instances_status" # echos available
if [ "available" = "$db_instances_status" ]; then