Jus*_*808 1 io-redirection shell-script command-substitution
我可以做到OUTPUT=$(grunt test)
,这会将输出放入OUTPUT
但它不再出现在屏幕上。我还需要看到输出,所以我不能等待然后echo $OUTPUT
.
如何捕获程序的输出并同时将其转到屏幕?
你可以尝试这样的事情:
exec 9>&1
OUTPUT=$(grunt test | tee /dev/fd/9)
exec 9>&-
Run Code Online (Sandbox Code Playgroud)
它将当前标准输出复制到文件描述符 9,用于tee
将grunt
的输出复制到该文件描述符,然后关闭临时文件描述符。