How to add a carriage return as a character to a file?

℡╲_俬逩灬. 提交于 2019-12-12 08:13:25

问题


I wanna have a string like:

blablbabla<carriage return goes here>

I mean the string should contain the carriage return. Is there any simple way to do it? Or if a write a program in c and use fputs with blablabla\r, does this do the trick?


回答1:


If you're using vim you can enter insert mode and type 'CTRL-v CTRL-m'. That ^M is the keyboard equivalent to \r. (see Insert the carriage return character in vim)

Inserting 0x0D in a hex editor will do the task.




回答2:


echo -ne "blablbabla\r" > /path/to/your/file




回答3:


SHELLVAR=$(echo -ne "blablabla\r")

See the echo man page — the -e option causes echo to interpret backslash escapes.

Also, at least in bash's normal edit mode, the same control-v control-m sequence works to insert a carriage return character literally; it will show as ^M



来源:https://stackoverflow.com/questions/7742340/how-to-add-a-carriage-return-as-a-character-to-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!