[comp.unix.shell] Is this a bug? SunOS 4.1.1 csh, which, and $?prompt

tar@math.ksu.edu (Tim Ramsey) (05/05/91)

With the following .cshrc:

if ($?prompt) then  # Execute only if interactive cshell
	stty tostop erase ^H kill ^U
endif

the command 

   which emacs

returns what I expect.  However, the command

   echo `which emacs`

gives "stty: TCGETS: Operation not supported on socket" -- the stty is
being executed.  Is this a bug, or a feature, or am I doing something
wrong?  I first tripped over this when I typed "strings `which bison`".

Thanks for any insight.

--
Tim Ramsey/system administrator/tar@math.ksu.edu/(913) 532-6750/2-7004 (FAX)
Department of Mathematics, Kansas State University, Manhattan KS 66506-2602

jik@athena.mit.edu (Jonathan I. Kamens) (05/06/91)

The "which" command needs to execute your .cshrc, in order to get its
hands on aliases and such, so it can tell you when it is aliased to
something.

Furthermore, it needs to execute the .cshrc with $prompt set, because
so many people put "if ($ $?prompt) exit" at the top of their .cshrc
file.

Most shell scripts don't have to pretend they're interactive.  "Which"
is a special case, and therefore has special problems :-).

How to solve it?  Well, one thing that comes to mind is not to put
stty commands in your .cshrc file.  They should be in your .login file
instead.  If that's not possible, then set a variable such as STTY_SET
after the first time you run stty, and then check if that variable is
set in .cshrc before doing it.  Something like this:

	if ($?prompt && (! $?STTY_SET)) then
		stty tostop erase ^H kill ^U
		setenv STTY_SET
	endif

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710