Jump to content

Reading variables from a file [solved]


Recommended Posts

Can any one tell me how to read variables from a text file so they can be used with in a bash script

 

ie text file has

 

 
serverone_host=amber 
serverone_ip=10.0.0.1 
servertwo_host=green 
servertwo_ip=10.0.0.2 
and so on

 

bash file picks out the different variables so rather then having to edit a load of scrips i would only have to edit the text file each time i deploy a system

 

gee i am asking the question and that doesn't make sense to me hope it make sense to some one out there

 

Regards

 

Ric

Link to comment
Share on other sites

textfile:

serverone_host=amber
serverone_ip=10.0.0.1
servertwo_host=green
servertwo_ip=10.0.0.2

 

text.sh:

#!/bin/bash

. textfile

echo "$serverone_host"
echo "$serverone_ip"
echo "$servertwo_host"
echo "$servertwo_ip"

 

< omar ~ > ./text.sh
amber
10.0.0.1
green
10.0.0.2

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...