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
What does 'echo 0 > foo' mean?
提问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 > foo
overwrites 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 >> foo
will add 0
to the end of the file foo
, or create a file containing 0
if it doesn't exist.
该命令echo 0 >> foo
将添加0
到文件的末尾foo
,或者创建一个包含文件(0
如果它不存在)。
回答by j08691
It echoes 0
to 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 中,而不是在终端显示它,终端是标准输出的常用目的地。