Search code examples
linuxbashmultilineeof

Append multiline tab delimited text form bash script with EOF, EOT, EOL


I want to insert after a specific string occurrence a multi-line text. The expected output is:

configuration options:
<tab>option 1
<tab>option 2
<tab>option 3
<tab>option 4
<tab>option 5
<tab>option 6
<tab>option 7
<tab>option 8
<tab>option 9
<tab>option 10
<tab>option 11
<tab>option 12

All lines except from the first are delimited with a tab. I don't want to do this with several echo commands. I would prefer EOF, EOT, EOL but these do not write the tabs.

Currently I use that:

  cat >> /etc/conf/conf.conf <<-EOF
  <tab>configuration options
  <tab><tab>option 1
  <tab><tab>option 2
  <tab><tab>option 3
  <tab><tab>option 4
  <tab><tab>option 5
  <tab><tab>option 6
  <tab><tab>option 7
  <tab><tab>option 8
  <tab><tab>option 9
  <tab><tab>option 10
  <tab><tab>option 11
  <tab><tab>option 12
  EOF

But the second tab is ignored and not written to my file.


Solution

  • Remove the dash (-) from this line:

    cat >> /etc/conf/conf.conf <<-EOF
    

    And, maybe, use a better name for EOF:

    cat >> /etc/conf/conf.conf <<_list_of_options_
    configuration options
    <tab>option 1
    <tab>option 2
    <tab>option 3
    <tab>option 4
    <tab>option 5
    <tab>option 6
    <tab>option 7
    <tab>option 8
    <tab>option 9
    <tab>option 10
    <tab>option 11
    <tab>option 12
    _list_of_options_