小编ajo*_*org的帖子

当 stdout 重定向到文件时,将消耗的输出复制到 stdout

给定一个命令,其输出正由 grep 处理,我还希望将实际输出包含在日志文件中以进行调试。

例如,如果我有以下内容

useful=$(curl -s http://example.com/some/data | grep 'useful line')
echo "useful=$useful"
Run Code Online (Sandbox Code Playgroud)

我想看看

This page has a number of lines in it, but'
useful lines are the only ones I care about
except when something goes wrong and then
I'd really like to see what the heck was in
the output that grep consumed.
useful=useful lines are the only ones I care about
Run Code Online (Sandbox Code Playgroud)

可以像这样用 T 恤完成

useful=$(curl -s http://example.com/some/data | tee /proc/$$/fd/1 | grep 'useful line')
echo …
Run Code Online (Sandbox Code Playgroud)

bash io

6
推荐指数
1
解决办法
857
查看次数

标签 统计

bash ×1

io ×1