I am looking for a generic command line solution that would allow me to add or modify a configuration option inside a config file (ini like format).
Most linux configur
Augeas / augtool aims to do this, although you'll need the right lens for the type of file you're after (you can also write your own), for example, the Nginx lens.
It also has an API if required.
git config is actually a semi-generic INI interface.
❱ git config --file=/etc/default/nginx somegroup.ULIMIT '-n 4096'
❱ cat /etc/default/nginx
[somegroup]
ULIMIT = -n 4096
❱ git config --file=/etc/default/nginx somegroup.ULIMIT
"-n 4096"
It doesn't support adding top-level keys, though. All keys have to be placed in an INI style group, hence the "somegroup." above. That makes it unsuitable for your task, but I thought I'd mention it here for others finding their way here.
Try crudini. BTW I think this file is a shell file rather than an ini file, but crudini can still work in this case:
crudini --set /etc/default/nginx '' ULIMIT '"-n 4096"'