Difference between \n and \r?

前端 未结 10 782
予麋鹿
予麋鹿 2020-11-21 11:17

What’s the difference between \\n (newline) and \\r (carriage return)?

In particular, are there any practical differences between

10条回答
  •  臣服心动
    2020-11-21 12:10

    To complete,

    In a shell (bash) script, you can use \r to send cursor, in front on line and, of course \n to put cursor on a new line.

    For example, try :

    echo -en "AA--AA" ; echo -en "BB" ; echo -en "\rBB"
    
    • The first "echo" display AA--AA
    • The second : AA--AABB
    • The last : BB--AABB

    But don't forget to use -en as parameters.

提交回复
热议问题