shell 中怎么调用perl脚本

astraydog 2011-12-10 02:35:22
我有个文件夹,
下面有link.pl,t.sh
link.pl :
#!/usr/bin/perl

print "link perl\n";
system("sudo mkdir /home/clx/Test/hello");
print "link perl end \n"


t.sh :
#!/bin/bash
echo "hello world bash "
perl link.pl
command="perl link.pl"
echo "end bash "

显示的结果为:

hello world bash
": No such file or directory.pl
end bash
也就是
perl link.pl
command="perl link.pl"
运行不正确

该怎么写呢?
我记得我先前还是可以的。现在是在虚拟机中。
...全文
1744 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
空的 2011-12-14
  • 打赏
  • 举报
回复
这个虚拟机里装了perl没有,还有perl 的PATH 环境变量有么。。
astraydog 2011-12-13
  • 打赏
  • 举报
回复
在linux 上新建的文件就不会有问题了
freetstar 2011-12-10
  • 打赏
  • 举报
回复
": No such file or directory.pl


==================
你代码里那里出现了directory.pl这个文件
astraydog 2011-12-10
  • 打赏
  • 举报
回复
是因为我在windows建的txt文件,然后把后缀名改成.pl。.sh之类的
放到linux上就有问题
askandstudy 2011-12-10
  • 打赏
  • 举报
回复
应该可以执行啊:
[root@RHEL6A tmp]# more link.pl
#!/usr/bin/perl

print "link perl\n";
system("mkdir /tmp/perltest");
print "link perl end \n"

我用上面的脚本能在/tmp/目录下创建perltest目录,
如果你的脚本不能运行,是不是在perl脚本中运行sudo时的问题呢?sudo要输入口令?
system("sudo mkdir /home/clx/Test/hello");
askandstudy 2011-12-10
  • 打赏
  • 举报
回复
./link.pl
调用时写绝对路径或相对路径
askandstudy 2011-12-10
  • 打赏
  • 举报
回复 1
我不懂perl的,不过我试了下这样可以执行:


[root@RHEL6A tmp]# more link.pl
#!/usr/bin/perl

print "link perl\n";
#system("sudo mkdir /home/clx/Test/hello");
print "link perl end \n"
[root@RHEL6A tmp]# more t.sh
#!/bin/bash
echo "hello world bash "
./link.pl
#command="perl link.pl"
echo "end bash "

[root@RHEL6A tmp]# ./t.sh
hello world bash
link perl
link perl end
end bash
[root@RHEL6A tmp]#

23,116

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧