The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[Perl] Determine directory name ejdv Shell Programming and Scripting 2 07-03-2009 05:21 AM
Move a file from windows directory to unix directory kingpeejay Shell Programming and Scripting 1 06-19-2009 02:31 PM
directory -l filename perl millan Shell Programming and Scripting 4 02-12-2009 07:18 PM
how to use sed or perl command to find and replace a directory in a file wip_vasikaran UNIX for Dummies Questions & Answers 1 08-20-2008 07:22 AM
create a directory in perl aajan Shell Programming and Scripting 7 03-12-2008 02:56 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-24-2009
zedex zedex is offline
Registered User
  
 

Join Date: Feb 2007
Location: india,mumbai
Posts: 139
#!/usr/bin/env : perl no such file or directory

hi i have some perl scripts with shebang line as (#! /usr/bin/env perl ) instead of actual absolute path of perl ( i know why its that way ) everything works fine from command line , the problem is when i am trying to run those scripts from web ( local web tool ) it throws error as
Code:
/usr/bin/env : perl No such file or directory

even when i logged in to web user i tried to run it it was okay .... i googled for it but not getting answers only suggestions to change it to absolute path which i dont want to do. any suggestions ??
  #2 (permalink)  
Old 07-24-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,813
What is env? What you have is a shebang where perl is some kind of parameter or option. I'm guessing you find perl because it is in your PATH when you are logged on. a more standard shebang would be

Code:
/usr/bin/env/perl

assuming this actually points to the location of the perl exectuable.
  #3 (permalink)  
Old 07-24-2009
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,928
It because the perl interpreter is not in the search path of the user that owns the web server process.
You could consider:

1. Modifying your shebang (to point directly to the perl interpreter), for example:


Code:
#!/usr/bin/perl

or

2. Adding the perl interpreter's directory to the search path to the user that owns the web server process and continue to use the env program:

Code:
#!/usr/bin/env perl

  #4 (permalink)  
Old 07-24-2009
zedex zedex is offline
Registered User
  
 

Join Date: Feb 2007
Location: india,mumbai
Posts: 139
yup you are right...
PATH variable was not passed to fastcgi when starting a apache as it was not in path it used to throw error. just passed the variables now its working ..
thanks a lot
  #5 (permalink)  
Old 10-30-2009
sylwesterr sylwesterr is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 1
I would like to "dig" the subject a little bit more, because I have also problem with script using that way of shebang.
I have installed, on Solaris, system wide, Perl 5.8.7 and the script that uses env tool to launch perl interpreter looks for LibXML.pm in folders where used to be installed perl 5.8.4.
So i have two questions:
1. why one would use env tool to launch perl instead of launching perl directly?
2. how to modify the env's output?
  #6 (permalink)  
Old 10-30-2009
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,928
Quote:
Originally Posted by sylwesterr View Post
[...]
1. why one would use env tool to launch perl instead of launching perl directly?
You could need to call it that way when you don't have control over the owner of the apache process and/or
you want to use the same configuration file on more non identical systems.

Quote:
2. how to modify the env's output?
If the above is not true just modify the environment of the owner of the apache process and point directly to the desired Perl interpreter.

You will use /usr/bin/env ... when you are not sure where exactly the needed executable is located, but you're sure it can be found somewhere in the environment.
  #7 (permalink)  
Old 10-31-2009
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 717
Hi.

These are good questions, and it is useful to know the issues. As radoulov has written, the env in the shebang line

Code:
#!/usr/bin/env bash

promotes portability. I use that in a template for writing scripts because I use several environments, and the locations of bash, ksh, perl, etc., are not consistent. This is often true for posting scripts here in this forum because the questions do not always mention the environment, Linux, Solaris, AIX, etc., so I almost always use that for suggested solutions. The Linux documentation for env leaves much to be desired in my opinion. For more information on many subjects including the use of env, see "bash Cookbook", O'Reilly, page 321.

However, we need to balance portability and security. If you have a consistent environment, then, for bash scripts, the construct

Code:
#!/bin/bash -

will avoid certain security risks. See "bash Cookbook", page 283. The authors consider the risks of the env construct to be small, so I generally stay with that.

Best wishes for safety and portability ... cheers, drl
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0