One needs to have an introduction with the whole concept of "file descriptors" to understand this answer - What is a "file descriptor" and why we need it. If you already have such an introduction, skip to the answer below; don''t --- Please read my answer in this SE thread, and then comeback.
In the second way I presented in the question, we pass an heredoc to Bash on a file descriptor other than 0 (in this case - 5:
The first part of the phrase,
bash /dev/fd/5, represents a bash with file descriptor 5 as its input, and the second part,
5<< EOF, tells the shell to write the here-doc into that file descriptor.
- The heredoc hierarchy has nothing to do with the number of the relevant file descriptor.
- I gave the number 5 just because it's a nice number far from zero. AFAIK, you could give 50, or 500, or 50,000, and it would work the same way.