LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-08-2006, 12:31 AM   #1
imagineers7
Member
 
Registered: Mar 2006
Distribution: BackTrack, RHEL, FC, CentOS, IPCop, Ubuntu, 64Studio, Elive, Dream Linux, Trix Box
Posts: 310

Rep: Reputation: 30
howto pick bash variables from file


Hi there,

I wanted to pick a variable from a file dynamically, to be used
in following kind of loop

do
commands <variable to be taken from file>
done


file contains a list of variables to be used in the loop.

How can I use those in the loop dynamically?


Thanks in advance
 
Old 05-08-2006, 01:42 AM   #2
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
If you want variables from one file to other use

source filename

This will read the file filename and get all the variables.
 
Old 05-08-2006, 01:50 AM   #3
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 68
Easiest (non secure etc) way: store the file in form variable=value and in each iteration 'source' the file
 
Old 05-08-2006, 01:56 AM   #4
imagineers7
Member
 
Registered: Mar 2006
Distribution: BackTrack, RHEL, FC, CentOS, IPCop, Ubuntu, 64Studio, Elive, Dream Linux, Trix Box
Posts: 310

Original Poster
Rep: Reputation: 30
Lightbulb Got the answer

Hello again,

I am sorry guys better I would have searched before I posted my
problem.

For others who may need the same anwer:-
http://www.linuxquestions.org/questi...d.php?t=258523

http://www.linuxquestions.org/questi...d.php?t=365158

http://www.linuxquestions.org/questi...d.php?t=276564
As it is:-

billym.primadtpdev>cat ~/1

while read line;do
eval $line
done
echo $XX_abba $XX_beatle $XX_cloop


My implementation simplified:-

alive.sh:--------------------------------


echo Pinging $lnx
ping -c 1 $lnx
if [ $? != 0 ]; then
echo
echo
echo
echo OOPS $lnx is not responding
echo
echo
echo
fi

ser.dat:__________________________________________
myser1.mydom.com
myser15.mydom.com
myser11.mydom.com
myser12.mydom.com
myser21.mydom.com


up.sh:------------------------------------------------

#!/bin/bash
for line in `cat ser.dat`
do lnx=$line
export lnx
./alive.sh
done

___________________________________________________________
and then:-
./up.sh



Thanks in past
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH script Ė reading and writing variables to a separate file morrolan Programming 10 09-20-2005 07:45 AM
I need to pick out the first, last and how many from a file...?!!? vous Programming 3 03-22-2005 01:44 PM
Setting Bash Variables from outside data file llewis Programming 10 01-12-2005 04:30 AM
howto create a file based on date in bash rohan208 Linux - Newbie 2 05-07-2004 03:54 PM
Bash variables pk21 Programming 2 01-09-2003 03:31 PM


All times are GMT -5. The time now is 02:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration