Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试计算命令中的行数,并且我还希望看到它们经过的行。我最初的想法是使用tee命令:
tee
complicated_command | tee - | wc -l
但这只会使使用 GNU 的行数翻倍,tee或者将输出复制到-Solaris 上命名的文件中。
-
complicated_command | tee /dev/tty | wc -l
但请记住,如果您将其放在脚本中并重定向输出,它不会按照您的预期进行。
解决方案是tee直接到控制台,而不是STDOUT:
STDOUT
tty=`tty` complicated_command | tee $tty | wc -l