1

really simple question but I can't seem to Google it. I want to tee a HEREDOC into a file and expand new lines from the variable.

user@host:~$ NEWLINEVAR="foo\nbar"
user@host:~$ tee -a > /dev/null filename <<HEREDOC
${NEWLINEVAR}
HEREDOC

Current result:

user@host:~$ cat filename 
foo\nbar

Wanted result:

user@host:~$ cat filename 
foo
bar

EDIT: I oversimplified my question. Edited above so it's using the HEREDOC implementation I need an answer for.

Neekoy
  • 2,325
  • 5
  • 29
  • 48

1 Answers1

6

Try

echo -e ${NEWLINEVAR} | tee -a filename

The -e option tells echo to expand escape sequences.

Jon
  • 3,573
  • 2
  • 17
  • 24
  • Ah I oversimplified the question. I upvoted because you answered what I asked, but I'm actually using HEREDOC. I edited the OP to reflect the situation. – Neekoy Jul 06 '18 at 08:50