Cfoote7
Cfoote7

Reputation: 375

Bad For Loop Variable in bash with sql server

I've been using a program of mine written in bash to interact with a mysql database, I switched to microsoft sql server and now I have a very strange issue. The code below worked with mysql. With microsoft sql server I can see that it successfully pulls the count. My "echo $id" shows a value of 23 like it should but the issue is bash spits out " Syntax error: Bad for loop variable". I'm confused at why it's doing that 23 is an integer value. Please Help.

 id="`tsql -S Server\\SqlServerName -U Databas_Name -P Password -o q <<EOF
 use numbers
 go
 SELECT COUNT(*) FROM lotsa_numbers
 go
 quit
 EOF`"

 echo $id
 for (( c=0; c=>$id-1; c++ ))
 do
      echo $c
 done

Upvotes: 1

Views: 194

Answers (1)

Reinstate Monica Please
Reinstate Monica Please

Reputation: 11593

Issue was likely leading or trailing whitespace. Number of ways to deal with this, a simple one is using bash splitting by not quoting a variable (might cause a problem in some cases, but not if we're trying to get an integer)

id=$(echo $id)

Upvotes: 1

Related Questions