Link to home
Start Free TrialLog in
Avatar of TIMFOX123
TIMFOX123Flag for United States of America

asked on

I want a Here document that will set more than one variables

I would like to have data in a "here doc" and be able to set several variables from the matching here doc line

example:

Here doc

 fred,10.10.10.10,dell
barny,10.10.10.11,toshiba
wilma,10.10.10.12,hp

 

if `hostname`= barney
ip = 10.10.10.11
make = Toshiba

I want the matching row in the data to set all the variables.  

If this is not clear I can explain more


redhat 5,6,7
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Better try "grep":
==> cat m0
cat - <<! >here.txt
fred,10.10.10.10,dell
barny,10.10.10.11,toshiba
wilma,10.10.10.12,hp
!
IFS=','
grep 'barny' here.txt|read host ip make
echo "hostname=$host ip=$ip make=$make"

==> ./m0
hostname=barny ip=10.10.10.11 make=toshiba
==>

Open in new window

Avatar of TIMFOX123

ASKER

ozo this is perfect

Kidos