Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Permission Denied running perl executables

I am running OS X and, basically, I wanted to set up a directory where I could drop some Perl executables and use them without having to type

$perl /this/is/the/path/name.pl

every time I wanted to use one. So I modified my .bash_profile to add a filepath for a directory that sits on my desktop that I want to drop executables in. I modified my .bash_profile by adding

PATH=$PATH:/Users/Wes/Desktop/Perl_dir; export PATH

Now, it finds the Perl files I want but denies me permission to them like so

-bash: /Users/Wes/Desktop/Perl_dir/phylo.pl: Permission denied

How can I fix this? Thank you in advance.

like image 759
Wes Field Avatar asked Dec 07 '22 06:12

Wes Field


2 Answers

Make sure that the perl script itself is set to be executable. You can do this with a command like this:

chmod +x /Users/Wes/Desktop/Perl_dir/phylo.pl

And then make sure the first line of the script has an appropriate "hash-bang" line to invoke perl, something like:

#!/usr/bin/perl -w

With both of those in place, I think your scripts should start working. (Note: The -w isn't strictly necessary, and may cause warnings in your script. I do suggest it, though, for developing new perl code, since it encourages a certain brand of perl hygiene.)

like image 167
Joe Z Avatar answered Dec 11 '22 08:12

Joe Z


Apart from setting PATH correctly, you also need to:

  • make sure files are executable

    $ chmod +x /this/is/the/path/name.pl
    
  • check your "shebang line", i.e. first line of the script must contain absolute path to perl interpreter on your machine, like this:

    #!/usr/bin/perl
    # this will work in Linux distros
    

    To find out the path, use which command:

    $ which perl
    /path/to/perl
    
like image 30
Alois Mahdal Avatar answered Dec 11 '22 08:12

Alois Mahdal