I execute the following code in Bash:
bash /dev/fd/10 10<<-'SES' cat <<EMR >> /etc/apache2/apache2.conf # <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> EMR SES
But the execution breaks and I get:
warning: here-document at line 2 delimited by end-of-file (wanted `EMR')
- I don't understand what the error means and I already added
-between the operator and the name of the containing heredoc to allow tabulations.
- I made sure there are no spaces after the opener (operator+name) or after the delimiter.
Note: If you copy the code above to test it in your computer, you need to change all leading spaces to tabs (tabulations) as StackExchange changed the original tabulations to spaces.
Possible causes to rule out:
There are several possible causes for this, here are some I've ruled out:
1. Problematic hidden characters:
I edit the file with Notepad++ and I turned on the "Show all symbols" mode to make sure all indents are tabulation based (see red arrows) and that all End Of Line chars (EOLs) are
LF unix based (there aren't any
Moreover, the encoding is
UTF-8, so it's not an encoding problem.
2. Pseudo dash symbol (
It seems as the added hyphen (
<<-) doesn't do its job of stripping all leading tabs because when I manually delete all leading tabs whatsoever (or all leading tabs before each delimiter) the heredoc does work as expected. One can suggest that the hyphen isn't really a dash symbol, but why won't it be? I have no way to validate that.
3. Bash bug:
Other people not-using Windows, and using different Bash-containing Linux distros didn't have this, so this is most likely not a Bash bug. I've also tested this with the Bash development section at GNU.
Corrupted pasting of copied data from Notepad++ might be it:
If I paste the heredoc from Notepad++ into a
nano file, it seems the leading tabs are all in place - they aren't deleted are transformed into spaces in pasting.
cat script.sh | grep "^ " and
cat script.sh | grep -x '\s*EMR' (when done in the files directory), come out empty.
Yet, in a later pasting I found another corruption problem that is most likley to cause this (see my answer).