所以,假设我foo
在一个脚本中有一个命令,它既有返回值,又有我感兴趣的输出字符串,我想将它们存储到一个变量中(至少它的输出为变量,其返回值可用于条件)。
例如:
a=$(`foo`) # this stores the output of "foo"
if foo; then # this uses the return value
stuff...
fi
我能想到的捕获该输出的最好方法是使用一些临时文件:
if foo > $tmpfile; then
a=$(`cat $tmpfile`)
stuff...
fi
无论如何我可以简化它吗?