BTW this assumes that the config file is simple and there is no order needed between the various lines.
Main Topics
Browse All TopicsHello,
I'm new to shell scripting, but so far I love it :-)
here is my question
I want to find a way to read (or/and change if needed) a value from a config files (mostly will be located in /etc)
is there any easy way to do it?
basically it will be like 2 functions one to read the value to a variable in my script and the other is to change the value to any thing I give!
cheers,
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
@noci, nice and simple. Can I make one suggestion? In your grep, always ensure that you tie it to the first character position with ^, otherwise you may get more than 1 line returned:
Business Accounts
Answer for Membership
by: nociPosted on 2009-08-14 at 07:56:15ID: 25098681
writing to a file:
The cfgvar is the name of the config variable.
$VAL is the value you want to give it.
adding:
echo cfgvar=$VAL >>/etc/configfile
deleting a line
grep -v 'cfgvar=' /etc/configfile >/etc/configfile.1 ; mv /etc/configfile.1 /etc/configfile
updating can also be done by: (by first removing a line from the file and then add it back with a new one
(grep -v 'cfgvar=' /etc/configfile ; echo cfgvar=$VAL ) >/etc/configfile.1 ; mv /etc/configfile.1 /etc/configfile
reading can be done through
VAL=$( grep cfgvar= /etc/configfile | sed -e 's/cfgvar=//' )
Updating can also be done through sed.