Xref: utzoo comp.unix.questions:5841 comp.unix.wizards:6720 Path: utzoo!mnetor!uunet!umix!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!bbn!rochester!PT.CS.CMU.EDU!sei!sei.cmu.edu!pdb From: pdb@sei.cmu.edu (Patrick Barron) Newsgroups: comp.unix.questions,comp.unix.wizards Subject: Re: Weird things in csh (and kernel?) Message-ID: <4373@aw.sei.cmu.edu> Date: 27 Feb 88 07:41:09 GMT References: <1193@ark.cs.vu.nl> Sender: netnews@sei.cmu.edu Reply-To: pdb@sei.cmu.edu (Pat Barron) Organization: Carnegie-Mellon University, SEI, Pgh, Pa Lines: 41 In article <1193@ark.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: >Has anyone noticed the following oddities? >1) > % a.out < a.out > a.out: Text file busy. > % >Why shouldn't a process be able to read its text file? I can't reproduce this under Ultrix 1.2. >2) > % cat ~/.cshrc > echo echo hello > % cp /bin/echo . > % ./echo > echo > hello: Command not found. > % cat echo > echo hello > hello > % > >What kinda weird thing is going on here? >Shouldn't there be an error message "Text file busy." >in this case? This is actually pretty simple. When you redirect output to "echo", the file gets overwritten *before* "./echo" is executed. So, it ends up trying to execute an empty file. Since it doesn't have a valid magic number, and the execute bits are set (copying /bin/echo left them set, and overwriting the file didn't change that), it's assumed to be a shell script. Your .cshrc file gets executed, echoing "echo hello" using the C-shell's built-in echo. That goes into the file "./echo", and the shell then starts to execute commands from "./echo". (Why isn't the Bourne shell used to do this? The file does not start with "#!/bin/csh") That file now contains "echo hello", so the shell's "echo" echoes "hello". Remember, standard output is still the "./echo" file, so that gets tacked on to the end. The shell then reads the next command, which is "hello", and it complains "Command not found." --Pat.