lolibility
lolibility

Reputation: 2187

return two values from perl to bash variables

I am calling a perl script to calculate size and variation in bash script. Is there a way to return those two values to separated variables in bash, say $SIZE and $VAR. Only know how to return one value.

Upvotes: 1

Views: 1542

Answers (3)

michael501
michael501

Reputation: 1482

set -- $(perl yourscript)

size=$1
var=$2

Upvotes: 0

Michael Tabolsky
Michael Tabolsky

Reputation: 3597

you can only do that by evaluating perl's output e.g.:

from perl:

print "SIZE=1 VAR=blah"

then in shell script:

export `your perl script.pl`

Upvotes: 1

Sir Athos
Sir Athos

Reputation: 9867

Instead of returning (which is mainly used for an error/success code from the script), you can print your variables from the perl script, separated by, say, space, and then read them from bash:

#!/usr/bin/perl
$size=1;
$var=2;
print "$size $var\n";

and:

#!/bin/bash
read SIZE VAR <<<$(my_perl_script)
echo size: $SIZE var: $VAR

Upvotes: 7

Related Questions