我想在我的Bash脚本中将某个命令在终端上的输出捕获到一个变量中。我尝试了以下方法:
TEST_OUT=`the_command ARG1` #Nope
#Putting the line "the_command ARG1" into a separate script, testing2.sh,
TEST_OUT=$(./testing2.sh) #Nope
testing2.sh
TEST_OUT=$? #Nope
我非常确定当我运行时...
> the_command ARG1
当我在终端中运行时,它会将我想要捕获的信息完全打印到终端上。
感谢任何帮助!
TEST_OUT=$(the_command ARG1 2>&1)
。 - Shawn Chin