简体   繁体   中英

Can not pass arguments from shell script to Perl script

I have the next shell script which I have named run.sh

#!/usr/bin/perl -w
#!/bin/sh

BROL="/sc01a4/users/user/brol"
PID=$$

while read line
do
  echo "$line" >> $BROL/rolak/1_EUSLEM_MATE/Sarrera_Testua_$PID.xml
done < "${1:-/proc/${$}/fd/0}"

perl $BROL/rolak/NAGUSIA.pl $BROL $PID

This script runs NAGUSIA.pl with two arguments, the path BROL and the process id, variable PID .

#!/usr/bin/perl -w

use strict;
use warnings;

my $direktorioa = "$ARGV[0]";
my $prozesua = "$ARGV[1]";

use lib "$direktorioa/rolak/lib";
use SRL::NAGUSIA qw(Egokitu_Sarrera Predikatu_Identifikazioa Predikatu_Desanbiguazioa Argumentuak_Identifikatu Argumentuak_Sailkatu Sortu_Irteera);

Egokitu_Sarrera($prozesua, $direktorioa);
Predikatu_Identifikazioa($prozesua, $direktorioa);
Predikatu_Desanbiguazioa($prozesua, $direktorioa);
Argumentuak_Identifikatu($prozesua, $direktorioa);
Argumentuak_Sailkatu($prozesua, $direktorioa);
Sortu_Irteera($prozesua, $direktorioa);

The Perl script is supposed two receive these two arguments but the command line gives the next error:

Use of uninitialized value $direktorioa in concatenation (.) or string at /sc01a4/users/user/brol/rolak/NAGUSIA.pl line 9.

I use the next command in order to run the shell script:

cat brol/proba_fitxategiak/proba4.txt | sh brol/EHU-eustagger/run.sh | sh brol/rolak/run.sh

I am using Linux, not Windows. Why the Perl script does not receive the arguments passed by the shell script?

use statements are executed at compile-time, so

use lib "$direktorioa/rolak/lib";

is executed before

my $direktorioa = "$ARGV[0]";

Replace

use lib "$direktorioa/rolak/lib";

with

use lib "$ARGV[0]/rolak/lib";

That said, you should really be using the following anyway:

use FindBin qw( $RealBin );
use lib "$RealBin/lib";

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