0

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.

1
  • 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. Commented Jul 15, 2019 at 8:00

1 Answer 1

6

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 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.