How to add a carriage return as a character to a f

2019-03-29 07:41发布

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?

3条回答
手持菜刀,她持情操
2楼-- · 2019-03-29 08:09
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

查看更多
Anthone
3楼-- · 2019-03-29 08:17

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.

查看更多
趁早两清
4楼-- · 2019-03-29 08:17

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

查看更多
登录 后发表回答