Question

While browsing SO I sometimes see EOFD for example:

ftp -vn <$hostname> <<EOFD

Yes I tried Google with no luck, just in case you are wondering.

Was it helpful?

Solution

In the context of the question you reference, EOFD doesn't mean anything special, it's just the start of a bash here document.

From the Advanced Bash-Scripting Guide:

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.

So in that question, the author was sending commands to ftp as if using it interactively.

OTHER TIPS

Try again with these search terms: here document

The <<EOFD construct is a special type a redirection for shell scripts (Bourne, bash and I'm not sure what others) that tell the shell to treat the lines follow as the stdin stream until a line that consists of EOFD is seen.

The EOFD string is arbitrary - any unique token (or at least one that won't be in the stdin input stream).

Since these words are arbitrary, why would anyone write EOFD rather than the customary EOF?

(And, by the way, there is also the tradition of using the ! character:

cat <<!
Hello
world
!

)

EOFD might be useful if the text you're generating with a here document is itself a shell script which itself contains here documents, and those here documents already use EOF for delimiting:

cat <<EOFD
#!/bin/sh
# here doc script
cat <<EOF
Hello
World
EOF
EOFD

:)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top