如下代码:
1 #! /bin/bash
2 v1=$(cat <<End-of-message
3 -------------------------------------
4 This is line 1 of the message. |
5 This is line 2 of the message. |
6 This is line 3 of the message. |
7 This is line 4 of the message. |
8 This is the last line of the message.
9 -------------------------------------
10 End-of-message
11 )
12 echo "${v1}"
13 v2="line1\nline2"
14 echo "${v2}"
输出:
This is line 1 of the message. |
This is line 2 of the message. |
This is line 3 of the message. |
This is line 4 of the message. |
This is the last line of the message.
line1\nline2
疑问:为什么 echo "${v1}"输出内容时会输出换行,而 echo "${v2}"却不会输出换行(加上-e 参数可以正常输出换行)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.