防止“回声"从解释反斜杠转义 [英] Prevent "echo" from interpreting backslash escapes

查看:106
本文介绍了防止“回声"从解释反斜杠转义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向包含新行转义序列的文件回显某些内容,但是我希望它们保持转义状态.我正在寻找与这个问题基本相反的东西. >

I'd like to echo something to a file that contains new line escape sequences, however I would like them to remain escaped. I'm looking for basically the opposite to this question.

echo "part1\npart2" >> file

我想在文件中看起来像这样

I would like to look like this in the file

$ cat file
old
part1\npart2

但是看起来像

$ cat file
old
part1
part2

推荐答案

这是POSIX建议使用printf而不是echo的一个很好的例子(请参阅echo 1 .

This is a good example of why POSIX recommends using printf instead of echo (see here, under "application usage"): you don't know what you get with echo1.

您可以获得:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆