In many occations I have come across the need to type a special character on bash’s command line, like the ESC character, new line, backspace, control combinations etc.
Of course we all know that for characters like the new line/LF (ASCII: 012) we can use the abbreviation \n. Some other abbreviations can be found by checking man ascii.
When we need, though, to enter a more convoluted keycode or character combination e.g. CTRL-C or tab or ESc etc. it’s very handy to remember that by typing CTRL-V and then whatever keystroke you wish, the appropriate escape code will be presented in a usable way on your bash command line.
Check the following example. We assign the CTRL-C and Backspace control characters in the variable i and then inspect the contents of it using od.
dl@icarus:~$ i=”^C^?” #after the double quote type: CTRL-V CTRL-B CTRL-V Backspace
dl@icarus:~$ echo $i
dl@icarus:~$ echo $i | od -b
0000000 003 177 012
0000003
dl@icarus:~$
od confirms that the characters stored in i are 003=ETX (end of text) and 177=DEL. The 012=NEWLINE character is printed out by echo.
Did you notice that by pressing the Backspace character we got ascii character 177? According to the ascii table that is the DEL character. However bash translates it and uses it as backspace.
The reason is that the xterm terminfo entry (my console’s $TERM is set to xterm) in my debian etch declares key_backspace=\177.