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

后端 未结 2 943
既然无缘
既然无缘 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 07:53

    $ A=$(mysql -uanon -ppwd -db mydb -e "select count(*) from table1")
    $ echo $A
    

    In other words, use the $() syntax.

提交回复
热议问题