Perl脚本系列。 BASH,BATCH,壳牌?

时间:2013-03-15 15:10:44

标签: perl bash shell batch-file

我有一系列perl脚本,我想在unix系统上一个接一个地运行。我可以在文档中引用什么类型的文件? BASH,BATCH,Shell脚本文件?

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:1)

只需将用于手动运行的命令放在文件中(例如perlScripts.sh):

#!/bin/sh

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

然后从命令行:

$ sh perlScripts.sh

答案 1 :(得分: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解释器的一个实例。它还可以避免重复加载模块。

如果确实需要传递参数或捕获输出,您仍然可以在带有反引号或system的Perl文件中执行此操作:

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

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

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