For some reason I need to run a perl script in Bash. But there is a counter in perl which I want to use back in the shell script (parent). But for some reason I am not able to fetch it.
Can somebody please help me with this? (The only alternative I am doing is writing the perl return code in a file and then reading the file in shell script (parent) to fetch the value).
#!/bin/sh
cnt=1
echo "In Bash (cnt: $cnt)"
perl - $cnt <<'EOF'
#!/usr/bin/perl -w
my $cnt=shift;
while ($cnt<100) {
$cnt++;
}
print "In Perl (cnt: $cnt)\n";
exit $cnt;
EOF
echo "In Bash (cnt: $cnt)"
Output:
$ ./testPerl
In Bash (cnt: 1)
In Perl (cnt: 100)
In Bash (cnt: 1)