[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Reading a conf file
- From: Russell Haley <russ.haley@...>
- Date: Wed, 28 Sep 2016 22:19:15 -0700
About the saving of values: yes, it is important not to molest the
original file. I would like to be able to work with conf files in
FreeBSD lik rc.conf and leave them intact.
Russ
On Wed, Sep 28, 2016 at 6:15 PM, Valentin <vsl@dasdeck.com> wrote:
>> Okay all you smarty pants (tee hee)! I need to be able to replace the
>> value of a line item in said conf files. This was my terrible attempt
>> some moons ago:
>
> As Sean has already mentioned, instead of identifying and changing a
> particular line in your conf file, it would be much easier to just save
> your full configuration again - unless you care about white space and
> comments in the conf file. If not, the following minimal code would
> write your conf table back to such a "INI-like" conf file:
>
> function saveConfToFile (confTable, confFile)
> local f = io.open(confFile, 'w')
> if f==nil then return false end
> for k,v in pairs(confTable) do
> f:write(k..'='..v..'\n')
> end
> f:close()
> return true
> end
>
> Disclaimer: untested email code
>
> Valentin
>
>
>