Reputation: 120
What is this usage mean:
expect <<- DONE
...
DONE
as in eof not recognized in Expect Script
especially the <<-
part.
Upvotes: 3
Views: 439
Reputation: 124646
In man bash
, if you search for <<-
(by typing: /<<-
and Enter
), you will find:
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.
For example:
$ cat << EOF
> hello
> there
> EOF
hello
there
The same thing but using <<-
instead of <<
$ cat <<- EOF
> hello
> there
> EOF
hello
there
The leading TAB character on the "hello" line is stripped.
As the quotation from the man
page said,
this is useful in shell scripts, for example:
if cond; then
cat <<- EOF
hello
there
EOF
fi
It is customary to indent the lines within code blocks as in this if
statement, for better readability.
Without the <<-
operator syntax, we would be forced to write the above code like this:
if cond; then
cat << EOF
hello
there
EOF
fi
That's very unpleasant to read, and it gets much worse in a more complex realistic script.
Keep in mind though, as @glenn-jackman pointed out:
Note that only tab characters are removed, not arbitrary whitespace. Be careful that your text editor does not convert tabs to spaces.
Upvotes: 7