-1

This question already has an answer here:

I saw the following command:

sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxxxxxxx.mirror.aliyuncs.com"]
}
EOF

What is the hyphen (‐) used for? It works fine even i remove the hyphen.

marked as duplicate by Stephen Kitt, mosvy, muru, Anthony Geoghegan, derobert Jul 17 at 17:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • It will cause it to strip leading tabs (and only tabs, not spaces!) from each line from the here-document, and also recognize the delimiter (EOF) if preceded by tabs. – mosvy Jul 15 at 8:00
1

The hyphen/dash is used for telling the shell to remove any leading tab character from the here-document. This is documented by POSIX as part of the here-document redirection:

If the redirection operator is <<-, all leading <tab> characters shall be stripped from input lines and the line containing the trailing delimiter. [...]

The feature allows for creating slightly prettier scripts:

while some-condition; do

    some-command <<-END_INPUT
    some data
    goes here
    END_INPUT

done

(where each line in the here-document and the line containing the END_INPUT delimiter are indented using tabs), as opposed to

while some-condition; do

    some-command <<END_INPUT
some data
goes here
END_INPUT

done

Not the answer you're looking for? Browse other questions tagged or ask your own question.