2013-03-15 66 views

回答

1

只要把命令你会使用到一个文件中手动运行它们(比如,perlScripts.sh):

#!/bin/sh 

perl script1.pl 
perl script2.pl 
perl script3.pl 

然后在命令行:

$ sh perlScripts.sh 
+0

感谢,诚实地说,它是一个愚蠢的问题,我只是想知道与它的脚本文件被称为。编写文档,它会是一个bash文件,shell脚本等? – 2013-03-15 15:23:35

+0

“shell脚本”将是一个合适的通用名称。我提供的例子应该可以用于几乎所有可以想象的Unix shell。一个“bash脚本”将是一个特别针对'bash'的shell脚本(也就是说,可能只使用'bash'支持的功能),并以'#!/ bin/bash'开头。 – chepner 2013-03-15 15:48:08

0

考虑使用Perl本身运行所有的脚本。如果脚本不带命令行参数,你可以简单地使用:

do 'script1.pl'; 
do 'script2.pl'; 

do 'file_name' basically copies the file's code into the current script and executes it。它给每个文件自己的范围,但是,所以变量不会冲突。

这种方法更高效,因为它只启动Perl解释器的一个实例。它也将避免重复加载模块。

如果你确实需要传递参数或捕获输出,你仍然可以做一个Perl,以反引号或system文件:

my $output = `script3.pl file1.txt`; #If the output is needed. 

system("script3.pl","file1.txt"); #If the output is not needed. 

这类似于使用shell脚本。但是,它是跨平台兼容的。这意味着你的脚本只依赖于Perl,而没有其他外部程序。它允许您轻松地为调用脚本添加功能。