More On The stty Command

Except for stty, all of the non-interactive UNIX programs executed so far have been run by the exec command. Compare:

exec kill −9 $pid
exec cat /etc/motd
exec touch foo
stty raw

It is possible to execute stty via exec on some systems but the required redirection is system dependent. Some stty implementations are sensitive to any redirection of standard error while other implementations require the standard error be redirected in order to catch errors. There is no way to call stty with exec that is both portable and reliable.

Expect addresses this problem by providing a built-in stty that uses the native UNIX stty command with redirection defined appropriately for your system. Additional redirection should be omitted if you want to affect the controlling terminal. For example, the following command disables echoing on the controlling terminal.

stty -echo

Because Expect’s stty command in turn calls your native stty command, you can pass to Expect’s stty any arguments already understood by your native stty. That means that vendor or site-dependent arguments can be used with Expect’s stty. On the other hand, if you want your scripts to be portable, you should stick with the POSIX 1003.2 stty arguments or perhaps even those from the archaic-but-last-common-to-all-UNIX Version 7.

For a number of reasons, Expect’s stty command recognizes several stty arguments. When the arguments are recognized, Expect’s stty command changes the terminal modes without calling the ...

Get Exploring Expect now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.