inconsistency on read/execute permissions for shell procedures

Steve D. Miller steve at tove.UUCP
Sat Jul 6 09:20:53 AEST 1985


In article <761 at wanginst.UUCP> gill at wanginst.UUCP (Timothy Gill) writes:
>All of the UNIX documentation I read states that programs and other
>executable files (shell procedures) are equivalent.  Yet I find that a
>file with the permissions
>
>	-rwx--x--- 
>
>will execute for members of my group if it is a program but will not
>execute if it is a shell procedure.  For a shell procedure to run for
>those users, there must also be read permission on the file:
>
>	-rwxr-x---
>
>This is the case when my interactive shell is either "sh" or "csh".
>
>This is clearly inconsistent.  Some people have tried to explain it to
>me by saying that a shell procedure must be "read" by the shell to be
>executed and that this is the reason the read permission must be there;
>if this is so, why cannot the same reasoning me made for program
>files?  They have to be "read" just as much as shell procedures.

   The problem is that when you run a shell script, the code that
actually starts things running looks at the first few bytes of the
file and decides whether or not it is a shell script.  If it is, then
the shell (sh, csh, or whatever) is executed so that the file is
its input.  For example, say you have a script named xyzzy that looks
like:

	#! /bin/csh <optional args>
	echo "Help Me Spock"
		.
		.
		.

   When the process is started, it is invoked as if you had typed
"/bin/csh xyzzy xyzzy <args>" (you can see this if you do a "ps"; I'm
not sure of the exact format, but that's the general idea).  Therefore,
the shell actually does an open() on xyzzy in an attempt to read
the commands there.  As one might expect, the open fails with 
"permission denied".

   I admit that it's inconvenient; maybe someone else has a better
workaround than the one I use (I rewrite it in C).
-- 
Spoken: Steve Miller 	ARPA:	steve at maryland	Phone: +1-301-454-4251
CSNet:	steve at umcp-cs 	UUCP:	{seismo,allegra}!umcp-cs!steve
USPS: Computer Science Dept., University of Maryland, College Park, MD 20742



More information about the Comp.unix mailing list