Define multiple variables in just one row

3

I would like to make a parser with just one line and break a string into several variables. In the string I will parse, the default is that each field is separated by a comma.

On several lines, the code to do what I want would be like this:

hostname='echo $tripa | cut -d, -f1'
ip='echo $tripa | cut -d, -f2'
serial='echo $tripa | cut -d, -f3'

Is there a way to do this in just one line (without repeating the command cut several times, one for each variable)?

    
asked by anonymous 03.03.2014 / 18:49

1 answer

1

I'm not sure if it will work for you.

tripa="meu host,127.0.0.1,abc"
IFS=',' read hostname ip serial <<<"$tripa"
echo -e "$hostname\n$ip\n$serial"

I found this response here

    
04.03.2014 / 00:32