I tried to solve this issue in the last couple of days and finally found a solution :)
\x1b\r and \x1d\r did not work for me. I found a solution here: Using a control character in a script with tr and echo
I used the following code:
escseq=`echo 'e' | tr 'e' '\035'`
Use $escseq to get Ctrl +].
How it works:
If your echo cannot directly control control characters, tr can do this for you. tr understands octal sequences. Create your output echo symbols that you don't need, and tr convert them to control characters you want.
For example, to make the 4-character sequence ESCape CTRL-a [CTRL-w, use the following command:
escseq=`echo 'ea[w' | tr 'eaw' '\033\001\027'`
tr reads four characters down the echo channel; it translates e to ESCape (octal 033), a to CTRL-a (octal 001) and w to CTRL-w (octal 027). The left bracket does not change; tr prints it as is.
Note. This is extremely useful if you want to automate logging out of a telnet session using a shell script.
source share