simulating keypress in shell

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

Preferably something already in base.
 
^ 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.
 
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.
 
Yes they are, but that's off topic. tmux and screen operate with pseudo-terminals also. Same principle.
 
Back
Top