0

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?

5
  • That's not the problem and perl script does receive the value. Put a print at line 7. print "direktorioa : $direktorioa \n"; to verify that. Commented Mar 16, 2017 at 18:57
  • I put the print but it is ignored and the error from line 9 persists. Commented Mar 16, 2017 at 19:01
  • 2
    What's with the perl shebang in run.sh? Commented Mar 16, 2017 at 19:20
  • 2
    Naming all your shell programs run.sh won't help you to find errors. Commented Mar 16, 2017 at 19:37
  • 2
    "I put the print but it is ignored" I suspect that you are editing the wrong run.sh. That is a result of having at least two programs called run.sh and possibly more. Commented Mar 16, 2017 at 19:40

1 Answer 1

5

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";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.