我在浏览SO时,有时会看到EOFD这个词,例如:
ftp -vn <$hostname> <<EOFD
是的,我尝试过谷歌搜索,但没有找到答案,以防你想知道。
我在浏览SO时,有时会看到EOFD这个词,例如:
ftp -vn <$hostname> <<EOFD
是的,我尝试过谷歌搜索,但没有找到答案,以防你想知道。
EOFD
没有特别的含义,它只是bash 这里文档的开头。在那个问题中,作者像交互式使用一样向A here document is a special-purpose code block. It uses a form of I/O redirection to feed a command list to an interactive program or a command, such as ftp, cat, or the ex text editor.
COMMAND <<InputComesFromHERE ... ... ... InputComesFromHERE
A limit string delineates (frames) the command list. The special symbol
<<
precedes the limit string. This has the effect of redirecting the output of a command block into thestdin
of the program or command. It is similar tointeractive-program < command-file
, wherecommand-file
containscommand #1 command #2 ...
The
here document
equivalent looks like this:interactive-program <<LimitString command #1 command #2 ... LimitString
Choose a
limit string
sufficiently unusual that it will not occur anywhere in the command list and confuse matters.
ftp
发送命令。<<EOFD
构造是 shell 脚本(Bourne,bash 和其他我不确定的)中一种特殊的重定向类型,它告诉 shell 把跟随的行作为 stdin
流处理,直到看到一个由 EOFD
组成的行。
EOFD
字符串是任意的 - 任何唯一的令牌(或者至少不在 stdin
输入流中的令牌)。既然这些词是任意的,为什么有人会写EOFD
而不是传统的EOF
呢?
(顺便说一下,还有使用!
字符的传统:
cat <<!
Hello
world
!
)
EOFD
可能很有用,如果你使用 here document 生成的文本本身是一个 shell 脚本,该脚本本身包含 here document,并且那些 here document 已经使用 EOF
作为分隔符:
cat <<EOFD
#!/bin/sh
# here doc script
cat <<EOF
Hello
World
EOF
EOFD
:)
!
传统。EOF
和 end
(大小写均可)很常见,有些人在脚本中使用不同的结束标记来描述每个 here-document,可能是为了更容易找到它们。 - torek
D
的内容。但是EOF表示文件结束。 - hjpotter92<<xxx
是here-document的定界符,所以可能EOFD代表文件结尾定界符或文件结尾数据。 - potong