开发者

Removing leading \n while assaigning to a variable

开发者 https://www.devze.com 2023-01-20 19:12 出处:网络
I have a DB2 query in a shell script which return an integer value, but I am 开发者_Go百科unable to store it in a variable.

I have a DB2 query in a shell script which return an integer value, but I am 开发者_Go百科unable to store it in a variable.

temp1= echo db2 -x "select max(id) from work.work_tb"

I am getting this output when I run it, sh -x test.sh

  • db2 -x select max(id) from work.work_tb
  • echo 50
  • temp1= 50

So for some reason $temp1 is unable to get the value, I think its because the db2 query is returning value prefixed with \n. How do I get rid of the newline char and get the value to temp1?


No, that's not why.

temp1=`db2 -x "select max(id) from work.work_tb"`


emp1=$(echo db2 -x "select max(id) from work.work_tb")

or using backticks

emp1=`echo db2 -x "select max(id) from work.work_tb"`

In general, to remove newlines, you can pass it to tools like tr/sed etc

... | tr -d "\n"
0

精彩评论

暂无评论...
验证码 换一张
取 消