EOFD是什么意思?

4

我在浏览SO时,有时会看到EOFD这个词,例如:

ftp -vn <$hostname> <<EOFD

是的,我尝试过谷歌搜索,但没有找到答案,以防你想知道。


我不清楚关于D的内容。但是EOF表示文件结束。 - hjpotter92
2
数据结束了,也许?在这里文档中使用的标识符可以是任何你喜欢的东西。 - Keith Thompson
正如@blahdiblah所指出的那样,我在引用这个问题 - jdorfman
EOF代表“文件结尾”,而<<xxx是here-document的定界符,所以可能EOFD代表文件结尾定界符或文件结尾数据。 - potong
4个回答

5
你引用的问题的背景下,EOFD没有特别的含义,它只是bash 这里文档的开头。
来自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 the stdin of the program or command. It is similar to interactive-program < command-file, where command-file contains

command #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 发送命令。

3
请使用以下搜索词再试一次:here document。关于it技术的内容请参考此链接。

3
<<EOFD 构造是 shell 脚本(Bourne,bash 和其他我不确定的)中一种特殊的重定向类型,它告诉 shell 把跟随的行作为 stdin 流处理,直到看到一个由 EOFD 组成的行。 EOFD 字符串是任意的 - 任何唯一的令牌(或者至少不在 stdin 输入流中的令牌)。

1

既然这些词是任意的,为什么有人会写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

:)


我不认为我见过 ! 传统。EOFend(大小写均可)很常见,有些人在脚本中使用不同的结束标记来描述每个 here-document,可能是为了更容易找到它们。 - torek

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接