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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...