Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!lsuc!ncrcan!brian From: brian@ncrcan.UUCP Newsgroups: comp.unix.questions Subject: Re: Trick question Message-ID: <334@ncrcan.UUCP> Date: Mon, 19-Oct-87 18:27:48 EDT Article-I.D.: ncrcan.334 Posted: Mon Oct 19 18:27:48 1987 Date-Received: Tue, 20-Oct-87 05:46:15 EDT References: <666@portofix.liu.se> Reply-To: brian@ncrcan.UUCP (Brian Onn) Organization: NCR Canada Ltd., Mississauga, Ontario Lines: 50 In article <666@portofix.liu.se> kjepo@portofix.liu.se (Kjell Post) writes: >A little trick question for you all: what's happening here? > > % cat > \* > date > ^D > % chmod +x \* > % \* > Tue Oct 13 03:13:08 MET 1987 > % > % cat > + > date > ^D > % chmod +x + > % + > $ -- entered Bourne-shell > This one's easy. When the cshell goes to exec a program, it checks to see if it has a valid magic number and uses fork/exec if so. Otherwise it checks to see if the first character is '#' and if so assumes that the file is a cshell script and executes it directly. If not, the cshell assumes that the file is a Bourne shell script and passes the file off to the Bourne shell to be executed. The file '+' looks like a Bourne shell script to the cshell, and so the chell says: /bin/sh + the '+' being the filename the cshell wants to execute. Now in the Bourne shell, one can turn on or off certain options using - or + in front of the option letters. Your example above also produces the same results if you use '-' instead of '+'. 'sh -' is documented, 'sh +' is not. So the Bourne shell thinks you want to turn off some option, but you just didn't supply the option, or possibly this is the explicit opposite to 'sh -' (I haven't looked up the source, and especially don't want to dive into the horrendouse Bourne Shell code). If 'sh -' means execute the .profile, maybe 'sh +' explicitly means not to? Also, you can use any number of '+'s and '-'s, and you will end up in the Bourne shell. This may add more weight to the possibility of an opposite to 'sh -', as it seems to indicate how the command line in 'sh' in parsed for arguments. Anyone else care to comment more on this. -- +-------------------+--------------------------------------------------------+ | Brian Onn | UUCP:..!{uunet!mnetor, watmath!utai}!lsuc!ncrcan!brian | | NCR Canada Ltd. | INTERNET: brian@ncrcan.UUCP | +-------------------+--------------------------------------------------------+