linux – 在字符串变量中保存命令输出,保持换行符
发布时间:2020-12-13 23:07:44 所属栏目:Linux 来源:网络整理
导读:我有一个转换文件数据的脚本,为了更有效地工作,我想改变内存中的数据,然后将其转储到文件中. 我希望修改包含此文件的文件: This is a line this is other line 我使用sed命令来替换’’带’#’的符号: transform_output=$(eval "sed ${sed_args[@]} $file"
我有一个转换文件数据的脚本,为了更有效地工作,我想改变内存中的数据,然后将其转储到文件中.
我希望修改包含此文件的文件: > 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# # This is a line # this is other line 提前致谢 解决方法
>引用用于防止在空白处分词:
echo -e“$transform_output” {echo“#ADDED LINE#”; echo -e“$transform_output”}>文件 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |