Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-12-08
3
Medium Priority
?
86 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

618 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