Ich habe eine Variable $ date in Main.pl-Skript erstellt, das ich an Annotator.pl-Skript übergeben möchte. Ich verwende ein Shell-Skript, um Annotator.pl auszuführen. Ich kann nicht herausfinden, wie man $ date an Annotator.pl weitergibt. Wenn ich my $date = $ARGV[0];
in Annotator.pl ausführen, bekomme ich den Namen des aktuellen Verzeichnisses, aber $date = $ARGV[1];
gibt nichts zurück.Variable zwischen Skripten übergeben
Bitte beachten Sie den folgenden Code. Das Datum ist wichtig, weil es genau sein muss und ich nicht herausfinden kann, wie man es an Annotator.pl weitergibt. Danke für Ihre Hilfe.
Main.pl Script:
#!/usr/bin/perl -w
use strict;
use warnings;
my $sec; my $min; my $hour; my $mday; my $mon; my $year; my $wday; my $yday; my $isdst;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$mon=$mon+1; $year = 1900+$year;
if (length($mon)==1) {$mon="0".$mon;}
if (length($mday)==1) {$mday="0".$mday;}
if (length($hour)==1) {$hour="0".$hour;}
if (length($min)==1) {$min="0".$min;}
if (length($sec)==1) {$sec="0".$sec;}
my $date = "$mon"."_"."$mday"."_"."$year"."-".$hour.$min.$sec;
my $cmd5 = `perl MDL_unzip_annotate.sh /data/test_all_runs pVCF $date`; print "$cmd5";
Shell-Skript: MDL_unzip_annotate.sh die Annotator.pl
home="/data/test_all_runs" #location of the run directory from which the program is launched
scripts="/data/test_scripts"
datapath=$1 #this is called in Main.pl as [test_all_runs]
process=$2 #the process
if [[ "$process" == "pVCF" ]];then
cd $datapath
folders="$(ls)"
cd $scripts
for ff in $folders; do
dname=$ff
echo $dname
if [ ! -f $dname ];then
cmd2="perl Annotator.pl $dname"
echo $cmd2
cmd2=`perl Annotator.pl $dname`
echo $cmd2
fi
done
done
fi
Annotator.pl Skript ausgeführt wird: shell
#!perl
use strict;
use warnings;
my $date = $ARGV[1]; print "the date is######## ".$date."\n";
'perl MDL_unzip_annotate.sh/data/test_all_runs pVCF $ date' ist sehr gefährlich - wenn Sie Ihren Befehl in einen String verketten, heißt das' system() ', das' sh -c' mit dieser Zeichenkette als Argument, was bedeutet, dass Sie anfällig für Shell-Injection-Angriffe sind. Tu das nicht. –
Ich bin ein Neuling ... bitte schlagen Sie vor, wie Sie $ date an Annotator.pl übergeben. Danke – user3781528
Denken Sie darüber nach, was passiert, wenn Sie Ihr Jahr aus Benutzereingaben statt der Ortszeit bevölkern - wenn der Benutzer das Programm mit '1994 $ (rm -rf $ HOME)' als Jahr ausführt, wollen Sie das System nicht um 'rm' tatsächlich aufzurufen, aber das passiert, wenn diese Zeichenfolge an eine Shell übergeben wird - und literales Quotieren ist einfach zu umgehen. –