Alex Gao Alex Gao - 1 year ago 126
Bash Question

What does "cat > somefilename <<EOF" (particularly, the greater-than and double less-than symbols) do in shell?

Just came across the following command:

cat > <<EOF

But I'm not sure of the use of

Answer Source

<<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.

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

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 > indicates that output should be written to, this thus writes everything up to the next EOF into


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download