3 ms·
The whole motivation of this article is that if you "have a task poorly suited to Bash" your options are either abandon bash or write a custom Bash builtin. Thi
by theamk 5y ago
The whole motivation of this article is that if you "have a task poorly suited to Bash" your options are either abandon bash or write a custom Bash builtin. This is very much not true.
The most common way to extend bash is to write a function which generates bash code, and then eval the results of this functions. This is how ssh-agent injects keys in the current session. This is how openwrt implements its configuration system. And so on.
For the ini parsing specifically, one would write "ini2bash" tool which reads ini file, and prints out bash commands to set the variables. Then in the code, you'd do "eval $(ini2bash file.ini)" and get all your variables.
This has a ton of upsides: works with any bash version; can use your favorite language; easy to debug; your shell won't start segfaulting if you upgrade it and forget to rebuild the plugin; the code can be reused if you switch to a different language. The main downside is it needs an extra fork and that it cannot access un-exported variables, but a lot of times this is acceptable.