[X-Unix] The which command lies?

Eric F Crist ecrist at secure-computing.net
Tue Feb 16 10:45:56 PST 2010


On Feb 16, 2010, at 12:39:58, Steve Morris wrote:

> Eric F Crist> Not addressing the exact problem, but the one most likely to arise
>> 
>>> next: if you are executing Perl scripts, the path of the Perl
>>> interpreter is normally given in the first line.  This will override
>>> the version of Perl that is in your path.
>> 
>> Only the script is being executed directly, and not being called as an argument to the perl binary.
> 
> I'm not sure what you are trying to say here. It sounds backwards.
> Scripts can't be executed directly. They are text files. Except in
> very unusual cases microprocessors can't execute text files. Only the
> interpreter (the perl binary) gets "executed." The shell parses the
> first line of the script then launches the interpreter indicated there
> with the script path as an argument, probably via fork and exec or
> similar system calls. This can be confusing because perl modifies $0
> (from the C argv[0]) to reflect the name of the script rather than the
> name of the executable. In perl $^X is supposed to be the fully
> qualified perl binary name.

If you set a script as executable, and run it directly as in:
# /path/to/script.pl

The shbang, ie #! gets interpreted to pull the parser, in this thread, a perl binary.  If you execute it as an option, as in:
# /path/to/perl /path/to/script.pl

the /path/to/perl binary will execute/process the script, regardless of what's in the shbang.


---
Eric Crist






More information about the X-Unix mailing list