当前位置: 动力学知识库 > 问答 > 编程问答 >

linux - variable is returning two values, how to store them in different variable?

问题描述:

My variable is returning two values and i have to pass these values at the same time in a shell script.

echo $var

output :

23514

abcd

Now i have to run a shell script with 23514 and 'abcd' as arguments

sh sample.sh --id var1 --value var2

网友答案:

Use an array:

vars=($var)
sh sample.sh --id ${vars[0]} --value ${vars[1]}
网友答案:

Either use an array, as Barmar has mentioned;

or use read with here-string:

read var1 var2 <<< $var
网友答案:
var1=`echo $var | awk '{print $1}'`
var2=`echo $var | awk '{print $2}'`
分享给朋友:
您可能感兴趣的文章:
随机阅读: