我有一个 shell 脚本,可以 grep 一些数据。我想将结果打印到文件中,但这样做会阻止结果显示在终端上。有没有一种方法既可以在屏幕上打印结果,又可以写入文件。 预先感谢。
tee
命令。
示例:
[me@home]$ echo hello | tee out.txt
hello
[me@home]$ cat out.txt
hello
请注意,
echo
的标准输出会被打印出来并写入由thr tee
命令指定的文件中。
请注意,您可以将
-a
标志添加到 tee
以附加到输出文件
[me@home]$ echo hello | tee out.txt
hello
[me@home]$ echo hello again | tee -a out.txt
hello again
[me@home]$ cat out.txt
hello
hello again
这是另一种不带 Tee 的方法。
echo "some content" > /dev/tty > log_file.txt