Ric Posted March 7, 2005 Report Share Posted March 7, 2005 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 Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted March 7, 2005 Report Share Posted March 7, 2005 . data_file (If it's in the same directory as your script) . /full/path/to/data_file (If it's n a different directory) Note that there is a space between . and the filename. Quote Link to comment Share on other sites More sharing options...
Cannonfodder Posted March 8, 2005 Report Share Posted March 8, 2005 Are you asking to execute the file? Or read it in the manner of an .ini file? Read variable, get value, do something with it? Quote Link to comment Share on other sites More sharing options...
Ric Posted March 8, 2005 Author Report Share Posted March 8, 2005 Are you asking to execute the file? Or read it in the manner of an .ini file? Read variable, get value, do something with it? <{POST_SNAPBACK}> Read it as a .ini file Thanks Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted March 8, 2005 Report Share Posted March 8, 2005 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 Quote Link to comment Share on other sites More sharing options...
Ric Posted March 8, 2005 Author Report Share Posted March 8, 2005 Thats excactly what i needed, ive been trying to grep and awk my way thro it, this is so much easier. Thanks A Lot Ric Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.