本文翻译自:How can I have a newline in a string in sh?
This 这个
STR="Hello\nWorld"
echo $STR
produces as output 产生作为输出
Hello\nWorld
instead of 代替
Hello
World
What should I do to have a newline in a string? 如何在字符串中包含换行符?
Note: This question is not about echo . 注意: 此问题与echo无关。 I'm aware of echo -e
, but I'm looking for a solution that allows passing a string (which includes a newline) as an argument to other commands that do not have a similar option to interpret \\n
's as newlines. 我知道echo -e
,但是我正在寻找一种解决方案,该方案允许将字符串(包括换行符ÿ