Difference between \ n and \ r pending?

In this particular script, they are using \n



set password [lindex $argv 0]

spawn asadmin enable-secure-admin
expect "admin"
send "admin\n"
expect "password"
send "$password\n"
expect eof



Is it possible to use \r

? If not, what are the differences?


source to share

1 answer


- string, Ctrl-J or character 012. \r

- carriage return, Ctrl-M or character 015.

In an interactive unix context, when you type them (or mimic their input, as expected), they are interchangeable. Linefeed is a formal line terminator character, but tty devices usually translate carriage returns on line output to input. On your keyboard, BKWA (a large arrow key that can be labeled "enter" or "return") sends Ctrl-M, which the tty device will translate to Ctrl-J. If your BKWA is broken, you can type Ctrl-M or Ctrl-J and it will work just as well.

They are not interchangeable at the exit. As I said, linefeed is a formal line terminator character, so programs (and text files) will indicate the end of the line with a line feed. When the output of a string is printed to a tty, the tty will typically convert it to a return-return-return pair.

When characters actually reach the display device, a carriage return moves the cursor to the beginning of the line and linefeed moves it down the line.



All Articles