shell 如何將命令的執行結果重定向到變量

var1=$(command)

var2=`command`

 

# To save both stdout and stderr to a variable, you need add 2>&1 at the ending. 

var3=$(command 2>&1)

 

ref:

https://stackoverflow.com/questions/11087499/bash-how-do-you-capture-stderr-to-a-variable/11087523

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章