O'Reilly logo

Exploring Expect by Don Libes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required