本文介绍了"cat>某些文件名<<< EOF" (特别是大于号和小于号的双倍符号)在shell中做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是遇到了以下命令:

cat > myspider.py <<EOF

但是我不确定使用><<.

推荐答案

<<EOF是Heredoc的开始.在此行之后且在仅包含EOF的下一行之前的内容在stdin上馈送到进程cat.

<<EOF is the start of a heredoc. Content after this line and prior to the next line containing only EOF is fed on stdin to the process cat.

> myspider.py是标准输出重定向.如果myspider.py已经存在(并且是常规文件),它将被截断,并且cat的输出将被写入其中.

> myspider.py is a stdout redirection. myspider.py will be truncated if it already exists (and is a regular file), and output of cat will be written into it.

因为cat没有命令行参数(之所以出现这种情况,是因为重定向被解释为有关如何设置进程的shell指令,而不是作为参数传递给cat)从其输入中读取并写入其输出,<<EOF指示应将以下行作为输入写入到进程中,而>myspider.py指示应将输出写入myspider.py,因此将所有内容写入下一个EOF进入myspider.py.

Since cat with no command-line arguments (which is the case here because the redirections are interpreted as directives to the shell on how to set up the process, not passed to cat as arguments) reads from its input and writes to its output, the <<EOF indicates that following lines should be written into the process as input, and the >myspider.py indicates that output should be written to myspider.py, this thus writes everything up to the next EOF into myspider.py.

请参阅:

  • The bash-hackers redirection tutorial
  • The Wooledge wiki entry on Heredocs

这篇关于"cat&gt;某些文件名&lt;&lt;&lt; EOF&quot; (特别是大于号和小于号的双倍符号)在shell中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 16:32