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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
回答2:
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`
回答3:
set -- $(perl yourscript)
size=$1
var=$2