std.path.getName(): Screwy by design?

Jonathan M Davis jmdavisProg at gmx.com
Fri Mar 4 03:19:07 PST 2011


On Friday 04 March 2011 02:02:45 Kagamin wrote:
> Daniel Gibson Wrote:
> > >> The only way _anything_ is executable in *nix is if its executable
> > >> flag is set. Extensions mean _nothing_ as far as executability goes.
> > > 
> > > As you can see, there's an ambiguity here: script is not executed
> > > directly in the same sense as machine code, so it may be not called an
> > > execution and not require executable flag to be interpreted. Actual
> > > application beign executed is interpreter. So the question is whether
> > > a script have to be flagged executable in order to run interpreter on
> > > it.
> > 
> > On *nix: Yes. Scripts have to be flagged executable. (Of course you can
> > start a non-executable script with e.g. bash foo.sh)
> 
> I suppose, the flag on a script is checked "manually" by the shell, and on
> a binary - by the OS.

The "OS" means next to nothing in unix land. What's the OS? The kernel? The set 
of common utilities? The whole environment? What matters is how the command line 
shell is implemented and how file permissions work. Per how file permissions work, 
a file must have the executable flag set either for all or for the group that the 
user is in, or it must be set for the owner of the file and the user running the 
file must be the owner of the file. If it is executable for that user, then the 
shell will attempt execute it. If not, they're not allowed to. Another program 
could attempt to read it and do something with it assuming that the user has 
read permissions for the file, but it can't be directly executed.

So, in the case of a shell script, you have to have permission to execute the 
file if you wish to execute it, and you have to have permission to read it if you 
want to pass it to some other sort of executable (such as a command to start a 
new shell) in order to run it that way. But ultimately, whether an executable 
file is a binary or not is irrelevant.

- Jonathan M Davis 


More information about the Digitalmars-d mailing list