4

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.

4

3 回答 3

15

确保 perl 脚本本身设置为可执行。您可以使用如下命令执行此操作:

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

然后确保脚本的第一行有一个适当的“hash-bang”行来调用 perl,例如:

#!/usr/bin/perl -w

有了这两个,我认为你的脚本应该开始工作了。(注意:这-w不是绝对必要的,并且可能会在您的脚本中引起警告。不过,我建议它用于开发新的 perl 代码,因为它鼓励某种品牌的 perl 卫生。)

于 2013-07-08T09:19:36.493 回答
2

除了正确设置 PATH 外,您还需要:

  • 确保文件是可执行的

    $ chmod +x /this/is/the/path/name.pl
    
  • 检查您的“shebang line”,即脚本的第一行必须包含您机器上 perl 解释器的绝对路径,如下所示:

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

    要找出路径,请使用 which 命令:

    $ which perl
    /path/to/perl
    
于 2013-07-08T09:19:44.590 回答
-2

您可能需要使用 sudo 授权 chmod,试试这个:

sudo chmod u+x program_name
./program_name 

如果不是 sudo while chmod,则需要像这样运行:

sudo chmod u+x program_name
sudo ./program_name
于 2014-12-02T21:26:19.323 回答