Crudini
Crudini is a command line interface to .ini files.
Solution
crudini --set test1.ini test foo foobarbaz
Or, more generally,
crudini
--set FILENAME.INI SECTION PARAMETER VALUE
Details
Written in 2013 by Pádraig Brady, crudini has become a standard solution in the UNIX toolkit in the years since this question was first asked. Many GNU/Linux distributions prepackage crudini as part of the OS, making installation simple (e.g., apt install crudini
). It also works on Apple MacOS and Microsoft Windows.
I have used my own custom sed
scripts in the past, but crudini is easier, more powerful, and less likely to accidentally destroy my files.
See the crudini homepage for more details.
Dangers
While crudini is safer than sed
for most people, it is not perfect.
- Crudini does not have sed's
-i~
option to automatically create a backup file when operating in-place.
- It is way too easy to delete an entire section.
crudini --set config.ini foo x=3
will blithely create a line that says, x=3 =
.
[Reportedly this is fixed in the latest release.]
- Its handling of lists (comma separated values) is naive.
foo=foobarbaz
and notfoobarbaz=bar
, your code worked for me under Windows, mingw (MSYS), bash. Quoting is shell-dependent; try using single quotes ('
) around thesed
string rather than double-quotes ("
). – Isherwood-i
option.sed -i "/^foo=/s/=.*/=foobarbaz/" test1.ini
(note that the redirection<
has been removed from the command). – Angie