Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!amdcad!ames!hao!oddjob!gargoyle!ihnp4!alberta!sask!ejw From: ejw@sask.UUCP (Eric Woodsworth) Newsgroups: comp.unix.questions Subject: Re: Re: \"+\" filename -> /bin/sh ! Message-ID: <916@sask.UUCP> Date: Tue, 27-Oct-87 15:00:15 EST Article-I.D.: sask.916 Posted: Tue Oct 27 15:00:15 1987 Date-Received: Tue, 3-Nov-87 05:21:17 EST References: <18062@teknowledge-vaxc.ARPA> Organization: University of Saskatchewan Lines: 114 > > in article <3351@sol.ARPA>, ken@cs.rochester.edu (Ken Yap) says: >> >> Since + is a non-binary, you are effectively doing /bin/sh +. Try >> this: >> >> /bin/sh + >> >> and get an interactive sh. In fact any argument starting with + >> will get you the same result. >> >> My guess is that sh discards arguments starting with + so effectively >> you are doing just /bin/sh. This is on SunOS 3.4. >> >> Ken > > On Ultrix 1.2, from either /bin/csh or /bin/sh I get: > > +: +: cannot open > > On Sun OS 3.4: > > csh% /bin/sh + > +: Command not found > > sh$ /bin/sh + > sh$ > > On Sun OS 3.2, both csh and sh give you a /bin/sh subprocess. > > Mike Khaw I asked wylie@sask.UUCP what his opinion was on all this and he came up with the following explanation, which I think sheds more light than the past responses to date. ====================================================================== Date: Mon, 26 Oct 87 12:18:04 cst From: wylie@sask.UUCP (Kelly Wylie) Message-Id: <8710261818.AA24575@sask.USask.UUCP> To: zeus@pmbrc.UUCP Subject: Re: trick I tried it on kim (4.2 BSD) and skorpio (Pyramid) in both ucb and att mode. On kim and skorpio in ucb mode (i.e. 4.2 based) it behaved the same as on max - the date resulted from both. However in att mode (System V based) I got the behavior described in the message. As near as I can figure out, "+" is not a special character for 4.2 based sh. It is a special charater for System V based sh. Below is the section on the set command for both the System V sh and the BSD sh. Note the marked difference. I also noticed that there was a "/bin/sh +" visible when I did a ps in the att world with the sh running. I think what is happening is the following. When a command is given the csh looks at the file and determines that it is a shell script. Since the first few characters are not "#!" it forks a Bourne shell and gives the name of the file as the argument with the intention that the sh would execute the contents of the file. Up to this point it is the same for both att and ucb worlds. The difference occurs when the sh looks at its arguments. In the ucb world, the "+" is not a special character so it proceeds as expected, i.e. it executes the contents of the file. In the att world, the sh sees the "+" argument and thinks that it is a shell argument rather than a file name, so it invokes an interactive sh. It never looks at the contents of the file. ATT sh ------ set [ --ekntuvx [ arg ... ] ] -e Exit immediately if a command exits with a non- zero exit status. -k All keyword arguments are placed in the environment for a command, not just those that precede the command name. -n Read commands but do not execute them. -t Exit after reading and executing one command. -u Treat unset variables as an error when substituting. -v Print shell input lines as they are read. -x Print commands and their arguments as they are executed. -- Do not change any of the flags; useful in setting $1 to -. -------->> Using + rather than - causes these flags to be turned off. These flags can also be used upon invocation of the shell. The current set of flags may be found in $-. The remaining arguments are positional parameters and are assigned, in order, to $1, $2, .... If no arguments are given then the values of all names are printed. UCB sh ------ set [-eknptuvx [arg ...]] -e If non interactive, exit immediately if a command fails. -k All keyword arguments are placed in the environment for a command, not just those that precede the com- mand name. -n Read commands but do not execute them. -t Exit after reading and executing one command. -u Treat unset variables as an error when substituting. -v Print shell input lines as they are read. -x Print commands and their arguments as they are exe- cuted. - Turn off the -x and -v options. These flags can also be used upon invocation of the shell. The current set of flags may be found in $-. Remaining arguments are positional parameters and are assigned, in order, to $1, $2, etc. If no arguments are given, the values of all names are printed. Kelly