egberts / bash-ini-file Goto Github PK
View Code? Open in Web Editor NEWGet keyvalues by its section/keyword from an INI-format (v1.4) file in bash (also works with systemd, NetworkManager config files)
License: MIT License
Get keyvalues by its section/keyword from an INI-format (v1.4) file in bash (also works with systemd, NetworkManager config files)
License: MIT License
need to figure out how to display --help
in the modularize bash script file.
it may entail upgrading this modularized bash script into an actual standalone script that can take argument(s) of files as well optionally displaying example usages then quit, using --help
or -h
command line option.
Help text body would display at least a few of the most useful examples.
Hello,
Nice and helpful project!
I wanted to test this on my firefox profile, but had to struggle just a little bit until I found out how to use it:
nico@xantico:~$ source .local/bin/bash-ini-parser.sh
nico@xantico:~$ cd .mozilla/firefox
nico@xantico:~/.mozilla/firefox$ ini_file_read profiles.ini
nico@xantico:~/.mozilla/firefox$ cat profiles.ini
[Install46F492E0ACFF84D4]
Default=s25g8abr.dev-edition-default
Locked=1
[Install4F96D1932A9F858E]
Default=waxl9k8u.default
Locked=1
[Profile1]
Name=default-release
IsRelative=1
Path=v6gmyi1u.default-release
[Profile0]
Name=default
IsRelative=1
Path=waxl9k8u.default
Default=1
[General]
StartWithLastProfile=1
Version=2
nico@xantico:~/.mozilla/firefox$ ini_section_list profiles.ini
nico@xantico:~/.mozilla/firefox$ ini_file_read
nico@xantico:~/.mozilla/firefox$ ini_file_read --help
nico@xantico:~/.mozilla/firefox$ ini_file_read `cat profiles.ini`
nico@xantico:~/.mozilla/firefox$ cat profiles.ini | ini_file_read
nico@xantico:~/.mozilla/firefox$ ini_file_read "k1=val1"
[Default]k1=val1
nico@xantico:~/.mozilla/firefox$ ini_file_read "`cat profiles.ini`"
[Install46F492E0ACFF84D4]Default=s25g8abr.dev-edition-default
[Install46F492E0ACFF84D4]Locked=1
[Install4F96D1932A9F858E]Default=waxl9k8u.default
[Install4F96D1932A9F858E]Locked=1
[Profile1]Name=default-release
[Profile1]IsRelative=1
[Profile1]Path=v6gmyi1u.default-release
[Profile0]Name=default
[Profile0]IsRelative=1
[Profile0]Path=waxl9k8u.default
[Profile0]Default=1
[General]StartWithLastProfile=1
[General]Version=2
nico@xantico:~/.mozilla/firefox$
(Finally found out reading the tests). Maybe something like a simple
ini_file_read "`cat myfile.ini`"
(or whatever is better) somewhere in the README or from a --help
option, might be nice.
Thank you anyway, this was much shorter than re-creating it entirely myself :-)
I know, I know, I know.... //
inline comment is not yet supported.
But, but ... BUT I have a working Regex pattern for this. It is:
(((\x27[ \!\"\#\$\%\&\(\)\*\+\-\.\/0-9\:\;\<\=\>\?@A-Z\[\\\]\^\_\`a-z\|\~]*\x27\s*)|(\"[ \!\#\$\%\&\x27\(\)\*\+\-\.\/0-9\:\;\<\=\>\?@A-Z\[\\\]\^\_\`a-z\|\~]*\"\s*)|(\/([ \!\$\%\&\(\)\*\+\-\.0-9\:\<\=\>\?@A-Z\[\]\^\_\`a-z\|\~]+[ \!\$\%\&\(\)\*\+\-\.0-9\:\<\=\>\?@A-Z\[\]\^\_\`a-z\|\~]*)|([ \!\$\%\&\(\)\*\+\-\.0-9\:\<\=\>\?@A-Z\[\]\^\_\`a-z\|\~]*))*)*)([;#]+)*.*$
That regex has demonstrably worked on many online Regex testers:
Couldn't get it to work with the following online regex tester(s):
Just need a bit of major Bash-FU going on... and is on-going.
I was looking for bash handling of INI files rather than rolling my own and came across this which has some usable ideas.
However I find the returns on some of your functions to be backwards, for example:
ini_section_test returns 0 if the section doesn't exist and 1 if it does, which seems to got totally against posix shell conventions which is zero for true and non-zero for false.
to use your function as part of regular shell operations, the test has to be negated
if ! ini_section_test "${ini_data}" SectionName
then
echo "Section Exists"
else
echo "Section not Found"
fi
Which is highly counter intuitive: if not section exists then section exists??
Secondly I'd suggest being able to load the inifile into a global variable and never have to use it again, rather than passing ${ini_data} for every read or test, perhaps adding simple wrappers for the get/list functions that use the preloaded data. Just an idea...
Also generally INI files sections and keys are case-insensitive, not a deal breaker but an item of note.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.