I did google this topic and all results are talking about <<EOF
.
But I saw scripts using <<-EOF
, but I can not find anywehre by googling.
Thus, What is different between <<-EOF
and <<EOF
in bash script?
Thanks a lot.
Asked
Active
Viewed 2.0k times
9

Jeff Schaller
- 67,283
- 35
- 116
- 255

sgon00
- 367
-
See 3.6.6 Here Documents in the bash manual – glenn jackman May 01 '20 at 14:53
2 Answers
20
<<-EOF
will ignore leading tabs in your heredoc, while <<EOF
will not. Thus:
cat <<EOF
Line 1
Line 2
EOF
will produce
Line 1
Line 2
while
cat <<-EOF
Line 1
Line 2
EOF
produces
Line 1
Line 2

A. R.
- 346
5
If you use <<-EOF
, I recommend the man page of the Bourne Shell:
If, however, the hyphen (-) is appended to <<:
leading tabs are stripped from word before the shell input is read (but after parameter and command substitution is done on word);
leading tabs are stripped from the shell input as it is read and before each line is compared with word; and
shell input is read up to the first line that literally matches the resulting word, or to an EOF.
So <<-
allows to indent the content of the here document for better readability.

schily
- 19,173