Skip to content
Advertisement

Bash – How to print multi line strings (with ‘n’) using printf

i’m trying to print a multi line strings in printf this way

printf "hin"
printf "next line heren"

I can’t do the following

text_content="
hi
next line here
"

printf $text_content

Is there any other way?

Advertisement

Answer

Quoting the variable should do the trick. In your example, however, you are getting double newlines.

printf "$text_content"
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement