What does the following command do? In particular I don't understand the role of -
in input redirection.
cat <<-EOF | command $argument
first option
second option
EOF
Is it mandatory to have the -
in the input redirection?
From man bash
:
If the redirection operator is <<-, then all leading tab characters are stripped from input lines and the line containing delimiter. This allows here-documents within shell scripts to be indented in a natural fashion.
$ cat <<-EOF
foo
bar
EOF
foo
bar
In context to your question regarding - in Here document, I will like to add something in Chris answer above
cat - filename <<-EOF
foo
bar
EOF
Here if you notice in above code; there are 2 -
. Both have different purpose 1) -EOF
which truncates the leading tabs in the delimiter.
2) cat - filename
: which basically prints first stdin content (till delimiter is found) + filename content. cat specifically provides this -
to have control over the order of stdin and file content. In above case changing the command to cat filename -
will print filename and the stdin content (till delimiter is found)