我有一系列 perl 脚本,我想在 unix 系统上一个接一个地运行它们。这是什么类型的文件/我可以在文档中引用它吗?BASH、BATCH、Shell 脚本文件?
任何帮助,将不胜感激。
我有一系列 perl 脚本,我想在 unix 系统上一个接一个地运行它们。这是什么类型的文件/我可以在文档中引用它吗?BASH、BATCH、Shell 脚本文件?
任何帮助,将不胜感激。
只需将用于手动运行它们的命令放在一个文件中(例如,perlScripts.sh
):
#!/bin/sh
perl script1.pl
perl script2.pl
perl script3.pl
然后从命令行:
$ sh perlScripts.sh
Consider using Perl itself to run all of the scripts. If the scripts don't take command line arguments, you can simply use:
do 'script1.pl';
do 'script2.pl';
etc.
do 'file_name'
basically copies the file's code into the current script and executes it. It gives each file its own scope, however, so variables won't clash.
This approach is more efficient, because it starts only one instance of the Perl interpreter. It will also avoid repeated loading of modules.
If you do need to pass arguments or capture the output, you can still do it in a Perl file with backquotes or system
:
my $output = `script3.pl file1.txt`; #If the output is needed.
system("script3.pl","file1.txt"); #If the output is not needed.
This is similar to using a shell script. However, it is cross-platform compatible. It means your scripts only rely on Perl being present, and no other external programs. And it allows you to easily add functionality to the calling script.