2

cat > filename << EOF vs cat << EOF > filename

When I tested it, it looks like they are equivalent but I'm not fully understanding why that is the case.

I understand the purpose of this command is to continually STDOUT into filename until I type EOF and then CTRL-D.

cat > filename << EOF (in terms of its sequence) makes sense to me: output stuff into filename until I hit EOF to tell it to stop.

But I was surprised that cat << EOF > filename works too. I've been told that bash reads from left to right. In this case, how is my STDOUT getting to filename?

Cyrus
  • 84,225
  • 14
  • 89
  • 153

1 Answers1

0

<< EOF controls what goes to cat's stdin.

> filename controls where cat's stdout goes.

It doesn't matter which order the two are applied, the result is the same. And, of course, it's cat that handles copying its input to its output.

hobbs
  • 223,387
  • 19
  • 210
  • 288