jk-kim
jk-kim

Reputation: 1186

How do I pass ESC to stdin?

How do I pass Esc to stdin in shell, the Esc on a keyboard?

I have discovered that 0x1B or ^[ is the outputted result of Esc but how can I input Esc?

Upvotes: 4

Views: 2129

Answers (2)

clarkttfu
clarkttfu

Reputation: 625

Interactive shell

Windows: Ctrl-[

Linux/Mac(bash): Ctrl-V then ESC

Scripting

BASH: echo -e '\033[92mText In Light Green\033[0m'

Windows CMD: to be done..

Upvotes: 0

Thomas Dickey
Thomas Dickey

Reputation: 54583

On most keyboards, it can be entered as control[.

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

printf '\033'

and in GNU echo, you may do

echo -e '\e'

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

printf '\033' | myscript

Upvotes: 4

Related Questions