我想将输出保存到文件中,同时我也希望在屏幕上看到进度。
基本上tee
仅适用于单行。对此有什么解决方案吗?
[user@linux ~]$ cat -n test.sh
1 echo line 1 | tee out.txt
2 echo line 2 | tee out.txt
3 echo line 3 | tee out.txt
4 ls -lh out*
[user@linux ~]$
[user@linux ~]$ ./test.sh
line 1
line 2
line 3
-rw-r--r-- 1 user user 7 Mar 7 11:58 out.txt?
[user@linux ~]$
[user@linux ~]$ cat out.txt^M
line 3
[user@linux ~]$
[user@linux ~]$ cat out.txt
cat: out.txt: No such file or directory
[user@linux ~]$
我想要的是这样的。
[user@linux ~]$ ./test.sh
line 1
line 2
line 3
-rw-r--r-- 1 user user 7 Mar 7 11:58 out.txt
[user@linux ~]$
[user@linux ~]$ cat out.txt
line 1
line 2
line 3
-rw-r--r-- 1 user user 7 Mar 7 11:58 out.txt
[user@linux ~]$
答案 0 :(得分:1)
如果您可以在执行时添加T恤,它会执行此操作。像
这样的东西bash file.sh | tee OUT.txt
有了这个你不必用每个回声呼叫三通