Home > Software design >  To know hex number from a bash shell key or escape code letter
To know hex number from a bash shell key or escape code letter

Time:08-31

How to know hex number from a bash shell key or escape code letter when sed -n l not work on this ie. not give anything back, for backspace key?

e.g. as sed -n l work on alt-L

\033l$

for backspace key in .inputrc its escape letter is \b

Please help get the get hex number for it

CodePudding user response:

$ echo -e "murugesan \bopenssl"
murugesanopenssl
$ echo -ne "\b" | od -bx
0000000 010
           0008
0000001
$ echo -e "murugesan \010openssl"
murugesanopenssl

Hence \010 referring backspace.

cat "73550541.sh"
#!/bin/bash
echo Provide one character l
read -n 1 REPLY
echo -ne "$REPLY" | od -bx
echo Provide Two characters Alt l
read -n 1 REPLY
echo -ne "$REPLY" | od -bx
read -n 1 REPLY
echo -ne "$REPLY" | od -bx
$ ./73550541.sh
Provide one character l
l0000000 154
           006c
0000001
Provide Two characters Alt l
0000000 033
           001b
0000001
0000000 154
           006c
0000001
Hence we can set the same using
$ export PS1='\033[32m$LOGNAME@$HOSTNAME \033[33m$PWD \033[0m[ $? ]\n$ '
Here \033 => referring Ctrl V Ctrl [
32m referring the string 32m
33m referring the string 33m
  • Related