Daily Archives

One Article


Echoing multiline in linux terminal

Posted by Kevin Kivi on

There are at least three fun ways to echo multiline to a file. We are going to look at doing the output twice, the heredoc -method and writing multiline using double quotes.

1. Output twice
I think this is the simplest and most intuitive method if you are familiar with linux output redirection.

user@server:~/projects/blog_content$ echo "This file is" >> multiline.txt
user@server:~/projects/blog_content$ echo "multiline" >> multiline.txt
user@server:~/projects/blog_content$ cat multiline.txt
This file is

2. Heredoc -method
You can replace EOF with your choice of characters. It denotes the ending of your input.

user@server:~/projects/blog_content$ cat <<EOF >> sorcery.txt
> This is
user@server:~/projects/blog_content$ cat sorcery.txt
This is

3. Write multiline
Leaving the double quote open you can press enter and start a new line. This is my favorite method.

user@server:~/projects/blog_content$ echo "what is this
> magic" > magic.txt
user@server:~/projects/blog_content$ cat magic.txt
what is this