i'm trying to print a multi line strings in printf
this way
printf "hi\n"
printf "next line here\n"
I can't do the following
text_content="
hi
next line here
"
printf $text_content
Is there any other way?
i'm trying to print a multi line strings in printf
this way
printf "hi\n"
printf "next line here\n"
I can't do the following
text_content="
hi
next line here
"
printf $text_content
Is there any other way?
Quoting the variable should do the trick. In your example, however, you are getting double newlines.
printf "$text_content"
Here's another variation.
printf '%s\n' 'first line here' 'second line here'
You can add an arbitrary number of arguments; printf
will repeat the format string until all arguments are exhausted.
printf '%s\n' '#!/bin/sh' \
'for x; do' \
' echo "Welcome to my script!"' \
'done' >script.sh
If printf is not necessary, then you may use echo:
var="one\ntwo"
echo -e $var