The not-a-typewriter error is caused by running commands where there is no controlling tty device; that is, no
interactive terminal is present. This would be true for a script that runs in cron or has su - to run a batch job.
To prevent this, you need to start with /etc/profile and test for an
interactive tty device as in:
Code:
case $- in
*i* ) export INTERACTIVE=/sbin/true
;;
* ) export INTERACTIVE=/sbin/false
;;
esac
While this may seem cryptic, the shell understands whether it is
interactive or not and sets a flag (the i flag). The construct $- returns all the current flags that are set as a string and if the letter i appears in the string, the shell is
interactive. Another way is to test the terminal device with the tty(1) command as in:
Code:
if tty -s
then
export TTY=/sbin/true
else
export TTY=/sbin/false
fi
The choice of $TTY or $INTERACTIVE is arbitrary as far as names. In your /etc/profile (and .profile, etc.), you can then test for
interactive terminal prior to any settings that affect the terminal. A few of the common commands are:
stty, tput, and tabs. Here is an example:
Code:
if [ $TTY ]
then
/sbin/stty erase "^H" kill "^U"
/sbin/stty intr "^C" eof "^D"
/sbin/stty -parity ixoff
/sbin/stty susp \^Z dsusp \^Y
if [ -x /usr/bin/tabs ]
then
/usr/bin/tabs
else
echo "$0: The command \"/usr/bin/
tabs\" was not found."
fi