linux – 在字符串变量中保存命令输出,保持换行符

我有一个转换文件数据的脚本,为了更有效地工作,我想改变内存中的数据,然后将其转储到文件中.
我希望修改包含此文件的文件:

> This is a line
> this is other line

我使用sed命令来替换’>’带’#’的符号:

transform_output=$(eval "sed ${sed_args[@]} $file" 2>&1)
echo -e $transform_output

我得到输出:

# This is a line # this is other line

而不是我想要的输出是:

# This is a line
# this is other line

>如何将输出保存在保持换行符的字符串变量中?
>如何在包含“#ADDED LINE#”的变量的开头添加一行并将其保存在文件中?

(我想要获取的文件):

#ADDED LINE#
# This is a line
# this is other line

提前致谢

解决方法:

>引用用于防止在空白处分词:

echo -e“$transform_output”
>使用另一个echo对命令进行分组:

{echo“#ADDED LINE#”; echo -e“$transform_output”}>文件

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...