6

If you type echo -e '\eZ' and hit return in a shell running in an xterm, you'll see that the terminal emulator prints an obscure code 1;2c. This seems to indicate that xterm interprets the VT100 control sequence \eZ (ESC Z, return terminal ID) and acts accordingly.

Now, if you press ESC Z in the same console, nothing happens. Does this mean that it is not possible to send control characters directly using the keyboard?

I'm not sure what is happening here, because pressing CTRL s (control flow) does stop the console output until you press CTRL q. So why does CTRL s/q work and not ESC Z?

1
  • 1
    can you please mark the answer below as correct if you are satisfied with it? Apr 5, 2012 at 9:55

2 Answers 2

7

VT100s responded to character sequences sent to them as output. So echo'ing characters works because the terminal sees it as output. Typing characters is input; the terminal will respond only if the characters are echoed by the receiving computer. Your typical shell doesn't echo ESC, it interprets ESC as the prefix for some interactive input command. Run cat and type ESC Z RETURN and you'll see the usual VT100 response.

0
-2

Also, you can press CTL-V on the keyboard usually first to tell the terminal that you want it to pass an ESC directly in instead of using it. Of course, you still have to get it echoed back to you, so doesn't necessarily help in this case, but instances where, say, you're editing a file in VIM and want to include an escape code, that's a convenient way to do so.

3
  • 1
    True, but this isn't what the question is about. The question asks how to send a command to the terminal, not how to input a control character literally. Aug 16, 2012 at 17:57
  • @Gilles Umm, I think it is exactly about how to input a control character literally. He wants to input a control character by pressing ESC Z in the same console he ran echo -e '\eZ' in, right? Apr 6, 2018 at 2:03
  • @Nick No, as Kyle's answer explains, Ernest was trying to output ESC Z. Apr 6, 2018 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.