bash Shell 脚本:如何在控制台上将字符串写入文件和标准输出?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22713667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 00:45:30  来源:igfitidea点击:

Shell Script: How to write a string to file and to stdout on console?

bashshellcommand-lineshksh

提问by Catanzaro

How to write a string to file and to stdouton console?

如何将字符串写入文件和stdout控制台?

If I do

如果我做

echo "hello" > logfile.txt

I view only helloin logfile.txtbut how can I write helloalso on console of Linux?

我只能查看hellologfile.txt但如何hello在 Linux 控制台上也可以编写?

回答by Biffen

Use the teecommand:

使用tee命令:

echo "hello" | tee logfile.txt

回答by SuperNova

You can use >>to print in another file.

您可以使用>>在另一个文件中打印。

echo "hello" >> logfile.txt