0

When creating a file example in a bash script, you can use cat and a here document with EOF as delimiter:

cat <<EOF > example
1234
ABCD
EFGH
EOF

This looks quite complicated to a bash newbie, so would there be a clearer version to write this code?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
rubo77
  • 19,527
  • 31
  • 134
  • 226
  • 1
    What looks simpler? Using `echo "multiple lines of string" > example`, with the redirection before or after the multi-line string according to whim? – Jonathan Leffler Aug 11 '15 at 01:10

1 Answers1

3

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.

So this looks much cleaner:

cat <<-EOF > example
    1234
    ABCD
    EFGH
EOF

where the spaces before each line are TABs!

rubo77
  • 19,527
  • 31
  • 134
  • 226