4 ms·
"cat wasn't displaying anything" ? perhaps: "the terminal correctly displayed the file, overwriting the printed line at each CR, with the last line blank" htt
by h2odragon 3y ago
"cat wasn't displaying anything" ?
perhaps: "the terminal correctly displayed the file, overwriting the printed line at each CR, with the last line blank"
https://unix.stackexchange.com/questions/355559/bash-and-carriage-return-behavior https://unix.stackexchange.com/questions/355559/bash-and-car...
- benj111 3y agoThat over writes though. It doesn't delete. Foofoo\rbar\r Should show as barfoo With the cursor over the start of that line.
- dale_glass 3y agoIf there's no newline, cat won't output one, and bash will put the prompt right after: [dale@host ~]$ echo -n "hi" > test [dale@host ~]$ cat test hi[dale@host ~]$ If you add a \r, then the cursor goes back to the start of the line, and the prompt overwrites the "hi". [dale@host ~]$ echo -en "hi\r" > test [dale@host ~]$ cat test [dale@host ~]$
- h2odragon 3y agodepends on the terminal
- jstanley 3y agoWhat terminal interprets "\r" as "clear the line"? I would have thought that is considered a bug.
- fragmede 3y agomost of them do. it's what a /r means. it's how cli programs can easily output a spinning wheel/similar for busy status.
- jstanley 3y agoNo, "\r" means return the cursor to the start of the line without clearing the line. Try this: $ echo -ne "ooo\rf\n" foo If a "\r" cleared the line, you would just see a "f", not a "foo".
- fragmede 3y agoisn't that what I said?
- t-3 3y agoYou want to know how I know you never wrote your own text editor? Carriage return is a carriage return, not a delete or backspace or clear line.
- benj111 3y ago>Carriage return is a carriage return To be fair it isn't. On typewriters it also adds a new line. On Mac, it is (used to be?) the new line character. I don't know how non vt terminals handled it.
- fragmede 3y agowho said anything about clearing? I just meant that \r goes to the beginning of the line, so you can output a busy spinner
- t-3 3y ago> What terminal interprets "\r" as "clear the line"? I would have thought that is considered a bug. >> most of them do. it's what a /r means. it's how cli programs can easily output a spinning wheel/similar for busy status. You did.
- DonHopkins 3y agoYou want to know how I know you never wrote your own C program or terminal emulator? /r means "slash, then the letter r". \r means carriage return, which doesn't clear the line, just moves the cursor to the left margin. Unless you're on an Apple ][, in which case CHR$(13) moves to the beginning of the next line, but still doesn't clear anything. And CHR$(4) is where the real magic happens, but it has to follow a CHR$(13)! ]PRINT CHR$(4) + "INIT HELLO"
- dan-robertson 3y agoYeah except the file ends in \r so the OP may have had their prompt longer than any of the lines (e.g. [user@hostname cwd] $) such that they couldn’t tell.
- deleted 3y ago[deleted]