15

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.

1

2 Answers 2

28

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

If you use <<-EOF, I recommend the man page of the Bourne Shell:

If, however, the hyphen (-) is appended to <<:

  1. leading tabs are stripped from word before the shell input is read (but after parameter and command substitution is done on word);

  2. leading tabs are stripped from the shell input as it is read and before each line is compared with word; and

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.