我希望回显一个包含引号和换行符的字符串,例如" "我们对死神说了什么?\ n今天没有。" "
echo -e " "What do we say to the God of Death?\nNot today." "
当然不会工作。
除了在内部引号中添加/ s之外,我还能做一个输出显示:
"What do we say to the God of Death?
Not today."
谢谢!
答案 0 :(得分:1)
在不转义的情况下,不能将同一组引号括在一对引号中。
最简单的选择是使用ANSI-C quoting:
echo -e $'"What do we say to the God of Death?\nNot today."'
它产生:
"What do we say to the God of Death?
Not today."
如果您只想使用双引号,那么您需要逃避需要打印的内容:
echo -e "\"What do we say to the God of Death?\nNot today.\""
答案 1 :(得分:1)
试试这个,
echo -e '"What do we say to the God of Death?'"\n"'Not today."'
示例:
$ echo -e '"What do we say to the God of Death?'"\n"'Not today."'
"What do we say to the God of Death?
Not today."
单引号中包含的字符串不会在echo
命令中解析。因此"What do we say to the God of Death?
不会被解析。并且将解析包含在双引号内的字符串。所以这个\n
被解析了。