1

I cannot find much explanation regarding a notation in here documents. In my shell script, I am plotting a file with gnuplot.

This code works:

gnuplot <<- EOF
         set xlabel "square dimension (inches)"
         set ylabel "mean survival time (seconds)"
         set term png
         set output "${plot_file}.png"
         plot "beetle.dat" using 1:2
EOF

However, if I do not include the dash in <<- and just use <<, this code does not work and I get the following error:

./myscript: line 118: warning: here-document at line 104 delimited by end-of-file (wanted `EOF')
./myscript: line 119: syntax error: unexpected end of file

This question might have been asked before, however due to special characters not being recognized, I cannot search for it.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
mrQWERTY
  • 4,039
  • 13
  • 43
  • 91

1 Answers1

2

When you say "this code", is it that code - or is it indented ?

Heredocs by default look for a line containing ONLY the delimiter, so no leading tabs or spaces. What the "-" does is remove leading tabs, so you can indent the heredoc (both content and delimiter) prettily in line with the rest of your code.

So if your delimiter is actually indented in the code, it will only be found with the "-"

See 3.6.6 in https://www.gnu.org/software/bash/manual/html_node/Redirections.html

racraman
  • 4,988
  • 1
  • 16
  • 16
  • Its indented. I copied it straight from the source code. Actually, the first line is suppose to be indented at the same column as the rest of the lines until EOF. I'll fix it. – mrQWERTY Apr 18 '15 at 22:52