开发者社区 问答 正文

shell中如何将pg查询结果赋给变量(是将数据赋给变量,不带标题)

!/bin/bash

aaa=$(su - postgres -c "psql -d mydb <<EOF select count(*) from test.student; EOF") echo "$aaa"

执行结果: [root@localhost postgres]# ./test count

1

(1 row) 我只想要数字1,不要上下行的字符 哪问大神能指点一下,非常感谢

展开
收起
kun坤 2019-11-28 12:04:01 1472 分享 版权
1 条回答
写回答
取消 提交回答
  • -c 改为 -Atc

    2019-11-28 12:04:07
    赞同 展开评论