Bash - 如何使用 printf 打印多行字符串(带有 '\n') [英] Bash - How to print multi line strings (with '\n') using printf
本文介绍了Bash - 如何使用 printf 打印多行字符串(带有 '\n')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试以这种方式在 printf
中打印多行字符串
i'm trying to print a multi line strings in printf
this way
printf "hi\n"
printf "next line here\n"
我不能执行以下操作
text_content="
hi
next line here
"
printf $text_content
还有什么办法吗?
推荐答案
引用变量应该可以解决问题.但是,在您的示例中,您得到了双换行符.
Quoting the variable should do the trick. In your example, however, you are getting double newlines.
printf "$text_content"
这篇关于Bash - 如何使用 printf 打印多行字符串(带有 '\n')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文