Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/bin/sh perl -I /some/special/libpath:/another/special/libpath "$@"

Drop in an exec to get rid of a needless /bin/sh instance:

#!/bin/sh exec perl -I /some/special/libpath:/another/special/libpath "$@"

And if you have more than one perl, specify which one you want to start. Also do this if you are not sure what $ENV{'PATH'} may contain.

#!/bin/sh exec /usr/local/perl-5.42.99/bin/perl -I /some/special/libpath:/anothe +r/special/libpath "$@"

But then again, cbeckley++ is right, perl can do fine without a shell:

#!/usr/local/perl-5.42.99/bin/perl use lib '/some/special/libpath','/another/special/libpath'; # rest of the script here, unmodified

Perl does not even mind if you prefix those two lines to an existing script, the shebang (#!) line of the existing script will be parsed as a comment.

If you don't want to modify scripts, you can also use a perl script as a wrapper:

#!/usr/local/perl-5.42.99/bin/perl use lib '/some/special/libpath','/another/special/libpath'; require '/path/to/real/script.pl';

(untested)

This simple one assumes that script.pl returns a true value. Alternatively, use do $filename, but that needs more code for error handling:

#!/usr/local/perl-5.42.99/bin/perl use lib '/some/special/libpath','/another/special/libpath'; unless (defined(do '/path/to/real/script.pl')) { die "Could not parse script: $@" if $@; die "Could not read script: $!"; }

(untested)

Generally, if you run a script as root or setuid root, consider adding -T to the shebang line to enable taint mode (see perlsec).

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^2: Trouble finding modules from cron by afoken
in thread Trouble finding modules from cron by faineant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found