Question

I have the following lines in a script:

NR_OF_REQUESTS_IN_PROGRESS=$(db2 -x "select count(*) from my_table where date='$MY_DATE' and status = 'EXPECTED_STATUS' and id in ($CURRENT_ID, $OTHER_ID)" | awk '{print $1}')
while [[ $NR_OF_REQUESTS_IN_PROGRESS -gt 0 ]]; do
  [...]
done

Now this works perfectly in my env, yet when a colleague of mine tests it, he gets an arithmetic syntax error for that line. How come?

Was it helpful?

Solution

What does your colleague's screen show if you add set -vx before the assignment to NR_OF_REQ..s. ?

The problem is almost certainly that the call to db2 is not returning a numeric value.

Just remember, set -vx is your friend (even if it is rather unwieldy when dealing with large and/or nested while/for/if-then-else-fi blocks of code :-) )

IHTH

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top