bash “echo 0 > foo”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25769926/
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-18 11:20:04  来源:igfitidea点击:

What does 'echo 0 > foo' mean?

bashunix

提问by 0leg

I would like to know what does this code mean?

我想知道这段代码是什么意思?

echo 0 > foo

Completely new to Unix and Bash commands. Lots of stuff to learn, but need a quick answer to this question.

对 Unix 和 Bash 命令来说是全新的。很多东西要学习,但需要快速回答这个问题。

回答by James

The command echo 0 > foooverwrites whatever content is in the file foo- or creates it if it doesn't exist - and replaces it with 0.

该命令会echo 0 > foo覆盖文件中的任何内容foo- 或者如果它不存在则创建它 - 并将其替换为0.

The command echo 0 >> foowill add 0to the end of the file foo, or create a file containing 0if it doesn't exist.

该命令echo 0 >> foo将添加0到文件的末尾foo,或者创建一个包含文件(0如果它不存在)。

回答by j08691

It echoes 0to a file named foo. In other words, it redirects the output, 0, to a file named "foo", instead of showing it on the screen.

它回显0到一个名为foo. 换句话说,它将输出 0 重定向到名为“foo”的文件,而不是将其显示在屏幕上。

From a basic Wikipediaexample on redirection:

来自关于重定向的基本维基百科示例:

command1 > file1

executes command1, placing the output in file1, as opposed to displaying it at the terminal, which is the usual destination for standard output.

command1 > file1

执行 command1,将输出放在 file1 中,而不是在终端显示它,终端是标准输出的常用目的地。