1

I created this bash script and can't seem to figure out why my code inside of the if block isn't executing.

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

I followed examples from this How to compare strings in Bash

and here https://tecadmin.net/tutorial/bash/examples/check-if-two-strings-are-equal/

James
  • 9,694
  • 5
  • 32
  • 38

1 Answers1

1

You either are not getting to the if statement or else the variable doesn't contain what you think it does.

This snippet will help debug both...

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
John3136
  • 28,809
  • 4
  • 51
  • 69
  • Thanks for helping me debug. The actual value was being returned in quotes. it didn't execute because "available" doesn't equal available – James May 16 '19 at 00:15