Bash: How to invoke command and store the result in a variable?

后端 未结 2 945
既然无缘
既然无缘 2020-12-14 07:25

Basically I want to be able to invoke a given command, in this case mysql -uanon -ppwd -db mydb -e \"select count(*) from table1\". And then take this commands

2条回答
  •  情书的邮戳
    2020-12-14 08:01

    You most likely want to use batch mode (-B) and disable column names (--disable-column-names) for non-interactive mysql output:

    out=$(mysql -B -db mydb -uanon -ppwd --disable-column-names  -e "select count(*) from table1";)
    

提交回复
热议问题