Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何将命令行输出重定向到文件,但仍在命令行中显示它们?_Linux_Shell_Tcsh - Fatal编程技术网

Linux 如何将命令行输出重定向到文件,但仍在命令行中显示它们?

Linux 如何将命令行输出重定向到文件,但仍在命令行中显示它们?,linux,shell,tcsh,Linux,Shell,Tcsh,在tcsh中,我想将命令行输出重定向到一个文件,但我仍然想在命令行中显示它们 你查过了吗 ./MyCommand.sh 2>&1 | tee /tmp/Output.txt 我应该做这项工作。但我犯了一个错误,比如: Ambiguous output redirect 在bash中,我使用|& 不确定这对tcsh的效果如何,但这个问题目前还没有标记出来,希望它能帮助其他人 根据这一点,您不能在csh中这样做,而tcsh扩展了可能相关的使用2>&1组合stderr和stdout只

tcsh
中,我想将命令行输出重定向到一个文件,但我仍然想在命令行中显示它们

你查过了吗

./MyCommand.sh 2>&1 | tee /tmp/Output.txt
我应该做这项工作。但我犯了一个错误,比如:

Ambiguous output redirect

bash
中,我使用
|&
不确定这对
tcsh
的效果如何,但这个问题目前还没有标记出来,希望它能帮助其他人


根据这一点,您不能在
csh
中这样做,而
tcsh
扩展了可能相关的使用
2>&1
组合stderr和stdout只能在
bash
sh
中工作。它不适用于
csh
tcsh
。建议在处解决。

问题中不清楚您是只重定向stdout,还是重定向stdout和stderr

使用
|
将stdout重定向到
tee
(将其输出到文件和终端),使stderr保持不变(因此它只进入终端):

使用
|&
将“合并”stdout和stderr,并且
tee
将重定向到文件和终端:

./MyCommand.sh | tee /tmp/Output.txt
./MyCommand.sh |& tee /tmp/Output.txt

只有
/MyCommand.sh 2>&1
对你来说可以吗?