Solved

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

Posted on 2014-12-08
3
59 Views
Last Modified: 2016-11-23
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
0
Comment
Question by:TIMFOX123
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40488054
IFS=,
while read h i m ; do
  if [ `hostname` == $h ] ; then
    ip=$i
    make=$m
 fi
done << here
fred,10.10.10.10,dell
barny,10.10.10.11,toshiba
wilma,10.10.10.12,hp
here

Open in new window

If that code is in a file, you need to source it, not execute it
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 40489458
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

0
 

Author Closing Comment

by:TIMFOX123
ID: 40490288
ozo this is perfect

Kidos
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now