<分区>
我正在尝试将一段文本捕获到一个变量中,并保留换行符,然后回显它。
但是,当我捕获文本或显示文本时,换行符似乎没有得到维护。
关于如何实现这一点有什么想法吗?
示例:
#!/bin/bash
read -d '' my_var <<"BLOCK"
this
is
a
test
BLOCK
echo $my_var
输出:
this is a test
期望的输出:
this
is
a
test
<分区>
我正在尝试将一段文本捕获到一个变量中,并保留换行符,然后回显它。
但是,当我捕获文本或显示文本时,换行符似乎没有得到维护。
关于如何实现这一点有什么想法吗?
示例:
#!/bin/bash
read -d '' my_var <<"BLOCK"
this
is
a
test
BLOCK
echo $my_var
输出:
this is a test
期望的输出:
this
is
a
test
最佳答案
echo "$my_var"
关于linux - 如何在 bash 中优雅地存储和回显多行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2752654/