5 ms·
Catting a file will your terminal make interpret escape codes in the file. For instance: $ echo -e "\033]0;${USER} is an unfriendly person\007" > test-fil
by eurg 7y ago
Catting a file will your terminal make interpret escape codes in the file.
For instance:
$ echo -e "\033]0;${USER} is an unfriendly person\007" > test-file.txt
Then, many days later:
$ cat test-file.txt
will change your terminal title.
With less, you _can_ interpret escape codes, but usually you don't, and I consider this the correct default.
- tazard 7y agoThat's a surprising and interesting bit if knowledge, thanks
- joosters 7y ago'less -R' is useful because it will honour colour control codes while escaping other ones (like title changes, terminal bell, etc)
- ISL 7y agoTried it -- didn't work. Single-quoting didn't work either. Terminal is urxvt. What is clear is that $ cat test-file.txt does not print the initially-echoed text, but it is escaped and up to nefarious tasks.
- eurg 7y agoThe escape sequence is terminal specific. urxvt is likely different from xterm in this regard.
- enriquto 7y agoin your example it is not cat who "interprets" the escapes, but echo
- eurg 7y agoNeither one interprets the sequence, but cat will print the file unfiltered to stdout, and stdout is processed by your terminal, and then the terminal will interpret it. less filters before printing to the terminal.
- enriquto 7y agoI meant that "echo -e" transforms the four characters "\033" into a single byte, for example. Thus, the sequence is "interpreted" by echo. Then, the cat program just copies the bytes without looking at them. If you want "cat" to escape these bytes so that they are not seen by the terminal you can use the "-v" option.
- kortilla 7y agoThe sequence that translates to an escape code is interpreted by echo. The escape code is passed unfiltered by cat for the terminal to interpret.