简体   繁体   中英

Series of Perl Scripts. BASH, BATCH, Shell?

I have a series of perl scripts that I want to run one after another on a unix system. What type of file would this be / could I reference it as in documentation? BASH, BATCH, Shell Script File?

Any help would be appreciated.

Simply put the commands you would use to run them manually in a file (say, perlScripts.sh ):

#!/bin/sh

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

Then from the command line:

$ 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM