In my .bashrc I had:
PS1='\e]0;\u@\h:\w [`tty`]\a\u@\h:\w [`tty`]\n\$ '
On bash 2.x, this meant that every time I displayed my bash prompt it needed to run tty twice.
This had a nasty gotcha...
john@hostname:~ [/dev/pts/0]
$ bash --version ; echo "yes" | grep "no" ; echo $?
SunOS
GNU bash, version 2.03.0(1)-release (sparc-sun-solaris)
Copyright 1998 Free Software Foundation, Inc.
1
john@hostname:~ [/dev/pts/0]
$ echo "yes" | grep "no"
john@hostname:~ [/dev/pts/0]
$ echo $?
0
The echo $? on a line by itself was dutifully reporting the exit code of the last tty command executed in the PS1 variable!
Removing the commands from PS1 made the problem go away:
$ PS1="$ "
$ echo "yes" | grep "no" ; echo $?
1
$ echo "yes" | grep "no"
$ echo $?
1
It then behaves as expected...
(NB: I didn't seem to get the same problem in bash 3.x)
I have now changed my prompt to:
MYTTY=$(tty)
PS1='\e]0;\u@\h:\w [${MYTTY:5}]\a\u@\h:\w [${MYTTY:5}]\n\$ '