I was trying to solve this question since the past couple of days and finally found a solution :)
The \x1b\r
and \x1d\r
did not work for me. I found the solution here:Using 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 this works:
If your echo can't make control characters directly, the tr utility can do it for you. tr understands octal sequences, too. Make your echo output characters you don't want, and have tr translate them into the control characters you do want.
For example, to make the 4-character sequence ESCape CTRL-a [ CTRL-w , use a command like this:
escseq=`echo 'ea[w' | tr 'eaw' '\033\001\027'`
tr reads the four characters down the pipe from echo ; it translates the e into ESCape (octal 033), the a into CTRL-a (octal 001), and the w into CTRL-w (octal 027). The left bracket isn't changed; tr prints it as is.
Note: This is extremely useful if you want to automate logout of a telnet session using a shell script.