How do I pass ESC to stdin?

How do I pipe Escto stdin in the shell, Escon the keyboard?

I found that 0x1B

or ^[

is the output result Esc, but how can I enter Esc?

+3


source to share


1 answer


On most keyboards it can be entered as control [.

In a shell script, you can do this (this is part of the POSIX shell):

printf '\033'

      

and in GNU echo

you can do



echo -e '\e'

      

Piping to the script makes the script's standard input ("stdin"):

printf '\033' | myscript

      

+3


source







All Articles