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

1.6k Views Asked by At

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.

3

There are 3 best solutions below

0
On BEST ANSWER

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_
0
On

bash allows the following syntax, similar to EOF where the string in single quotes is not modified at all:

cat >> /etc/conf/conf.conf <<<'configuration options
<tab>option 1
<tab>option 2
<tab>option 3
<tab>option 4
'
0
On

Actually I found it out as a combination of the above answer: In order to keep the tab delimiter I had to remove the "-" before EOF and remove one tab from each line:

cat >> /etc/conf/conf.conf <<EOF
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
EOF