1752340 Members
6540 Online
108787 Solutions
New Discussion юеВ

Re: Paths After Shebang

 
SOLVED
Go to solution
sharner
Occasional Contributor

Paths After Shebang

On the HPUX, is it required that I provide a full path in my script after the shebang? I am running a perl script that starts out with #!perl, and am getting the following error: "-bash: ./DirTree.pl: perl: bad interpreter: No such file or directory". However, when I provide the full path to perl, everything works fine. BTW, perl is in my path and does work from the command line without typing the full path.
6 REPLIES 6
avizen9
Esteemed Contributor

Re: Paths After Shebang

Hello sharner,
check the perl actual path with below command.

which perl

and then set path with below command
export PATH=/usr/bin/perl:$PATH

here my perl is installed in /usr/bin/perl

thanks,
Dennis Handly
Acclaimed Contributor
Solution

Re: Paths After Shebang

>is it required that I provide a full path in my script after the shebang?

Yes, exec(2) is picky that way.
You could use this trick:
#!/usr/bin/env perl

No options are allowed on that line.
James R. Ferguson
Acclaimed Contributor

Re: Paths After Shebang

HI:

Most commonly, you declare '#!/usr/bin/perl' in your scripts and simply symlink the Perl binary accordingly. This allows your scripts to make a static declaration while your binaries are installed in various subdirectories of '/opt' or '/usr' as your needs dictate. As Dennis noted, the approach taken is to use '#!/usr/bin/env perl'.

Regards!

...JRF...

Dennis Handly
Acclaimed Contributor

Re: Paths After Shebang

>ME: Yes, exec(2) is picky that way.

This is mentioned in exec(2):
When the script file is executed, the system executes the specified interpreter as an executable object file. ... no path searching is done of the interpreter name.
James R. Ferguson
Acclaimed Contributor

Re: Paths After Shebang

Hi (again) Sharner:

You can limit your script's options a bit by using the "#!/usr/bin/env" shebang tecnhique.

For example attempting to add runtime options when the interpreter is explicitly specified will work:

#!/usr/bin/perl -l

...BUT _FAIL_ when written as:

#!/usr/bin/env perl -l

...since "perl -l" is passwd as one argument leading to the error:

No such file or directory: perl -l

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: Paths After Shebang

>JRF: BUT _FAIL_ when written as:

That's what I was trying to say. It is all explained in exec(2):
http://docs.hp.com/en/B2355-60130/exec.2.html