I have perl scripts starting with #!/usr/bin/perl or #!/usr/bin/env perl
First, what does the second version mean?
Second, I use Ubuntu. All the scripts are set as executables. When I try to run a script by simply invoking it’s name (e.g. ./script.pl) I get : No such file or directory. when I invoke by perl ./script.pl it runs fine.
Why?
The
#!/usr/bin/env perluses the standard POSIX toolenvto work around the “problem” that UNIX doesn’t support relative paths in shebang lines (AFAIK). Theenvtool can be used to start a program (in this case perl) after modifying environment variables. In this case, no variables are modified andenvthen searches the PATH for Perl and runs it. Thus a script with that particular shebang line will work even when Perl is not installed in/usr/binbut in some other path (which must be in the PATH variable).Then, you problem with
./script.plnot working: you said it has the executable bit(s) set, like withchmod +x script.pl? But does it also start with a shebang (#!) line ? That is, the very first two bytes must be#!and it must be followed by a file path (to perl). That is necessary to tell the kernel with which program to run this script. If you have done so, is the path correct ? You want to try the#!/usr/bin/env perlvariant 😉