This question already has an answer here:
- How can I have a newline in a string in sh? 10 answers
I have a bash script and I have a string with some \n
:
interfaces="auto lo\niface lo inet loopback\n\n..."
Then I try to write this into the interfaces file like so:
sudo bash -c "echo -e $interfaces > /etc/network/interfaces"
I use -e
to display the \n
's but if I open the file it doesn't show right but if I just output it to the terminal it works:
auto loniface lo inet loopbacknn...
bash -c
argument.bash
will see it as a literal newline, which is a command delimiter. – Barmar Feb 13 '17 at 9:46echo
it to the terminal it works but not in the file. I'll try the solution of @Barmar now. – WasteD Feb 13 '17 at 9:46