This can't be done in the way you're trying to do this.
It either needs a wrapper shell script that sets LD_LIBRARY_PATH
and then calls your perl script, or any user executing the script needs to have LD_LIBRARY_PATH
set correctly in the first place.
If doing the latter, then this can be managed globally by editing /etc/profile
and /etc/cshrc
(for ksh, sh, bash, csh and tcsh) shells. You can then test for the value of LD_LIBRARY_PATH
in your script and if not set/set incorrectly then print a friendly message to the user. Alternatively individual users can set this in their local .profile
/.cshrc
files.
Note: you haven't given any information about the environment or useres that might run this, so there's also the possibility that users may set LD_LIBRARY_PATH
to something they need. If you do check LD_LIBRARY_PATH
for a "good" value in your script, then keep in mind that several paths may have been specified, so you will need to parse this environment variable properly.