# simulating keypress in shell



## UNIXgod (Jul 18, 2011)

How would I script something that would pipe an interactive mod statement like 'ctrl-g c'

Preferably something already in base.


----------



## Zare (Jul 18, 2011)

http://en.wikipedia.org/wiki/Expect


----------



## poh-poh (Jul 18, 2011)

`$ echo '\^g c' | unvis`


----------



## Zare (Jul 18, 2011)

^ that's possible if program expects input from stdin. If it wants direct terminal input (like ssh and sudo), it's a no-go without terminal wrapper like expect. It acts as pseudo terminal (/dev/pts/X), emulating keystrokes and catching output. Target program doesn't recognize, or care, that it isn't commanded by human TTY or PTS.


----------



## poh-poh (Jul 18, 2011)

ssh, sudo, pam (su) are flexible enough to authenticate a user using other means, not only via plaintext password. And aside from Expect one can also simulate write from terminal inside tmux/screen, i.e. send-keys, at + stuff.


----------



## Zare (Jul 19, 2011)

Yes they are, but that's off topic. tmux and screen operate with pseudo-terminals also. Same principle.


----------

