[英]How to call shell script from perl script
我正在嘗試從 perl 腳本調用已經保存的 shell 腳本,但它不起作用。
1.pl:
#!/usr/bin/perl
#!/bin/csh -f
use warnings;
use Shell;
system ("/bin/sh commands.sh");
命令.sh:
#!/bin/csh -f
echo "calling shell script from perl script";
如果 commands.sh 是可執行的,那么您只需要:
#!/usr/bin/perl
system("/path/to/commands.sh")
如果 commands.sh 沒有設置可執行標志,則
#!/usr/bin/perl
system("/bin/csh /path/to/commands.sh");
所有其他代碼似乎都是多余的。
對我來說,shell 腳本的路徑時不時會發生變化,所以我將它保存在腳本頂部的一個變量中,以便於更新:
我們的$pathToShellScript = '/path/to/script.sh';
system("/bin/sh $pathToShellScript");
不知道為什么會出現這個錯誤:
sh: -c: line 0: unexpected EOF while looking for matching
''` 時sh: -c: line 0: unexpected EOF while looking for matching
雖然以下有效: system ("/bin/sh", "$renamingScript");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.