相关疑难解决方法(0)

带有额外空间的多行字符串(保留缩进)

我想使用以下内容将一些预定义的文本写入文件:

text="this is line one\n
this is line two\n
this is line three"

echo -e $text > filename
Run Code Online (Sandbox Code Playgroud)

我期待这样的事情:

this is line one
this is line two
this is line three
Run Code Online (Sandbox Code Playgroud)

但得到了这个:

this is line one
 this is line two
 this is line three
Run Code Online (Sandbox Code Playgroud)

我很肯定每个人都没有空间\n,但额外的空间是如何产生的?

string bash shell echo

353
推荐指数
8
解决办法
39万
查看次数

标签 统计

bash ×1

echo ×1

shell ×1

string ×1