سؤال

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.

هل كانت مفيدة؟

المحلول

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.)

نصائح أخرى

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
    

you may need to authorize the chmod using sudo, try this:

sudo chmod u+x program_name
./program_name 

If not sudo while chmod, you need to run like this:

sudo chmod u+x program_name
sudo ./program_name
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top