rudimeier / bash_ini_parser Goto Github PK
View Code? Open in Web Editor NEWsimple INI file parser
License: Other
simple INI file parser
License: Other
Add INI__ALL_SECTIONS can be used in such satution:
Say I want to backup a list of mysql databases, and each of them have a different username and password, and the list of databases can be grow in the future, so I configure all databases in a ini file like this:
[db01]
name=db-host01
username=user1
password=pwd01
[db02]
name=db-host2
username=user2
password=pwd2
And in the backup script I can use some thing like
for db in `echo INI__ALL_SECTIONS`; do
name="INI__${db}__name"
echo "username of $db is ${!name}"
done
So everytime I need add a new database for backup, I only need to add a section in the ini file without change the backup sctipt.
In a script with "set -o errexit" the read_ini will fail. As a work-around, turn off errexit before using read_ini:
set +o errexit
read_ini ~/.script.ini
set -o errexit
The substitution for the escape of ' not work.
I propose this correction :
diff --git a/read_ini.sh b/read_ini.sh
index 06b1bc8..2ae2a85 100755
--- a/read_ini.sh
+++ b/read_ini.sh
@@ -270,7 +270,7 @@ function read_ini()
# enclose the value in single quotes and escape any
# single quotes and backslashes that may be in the value
VAL="${VAL//\\/\\\\}"
- VAL="\$'${VAL/\'/\\\'}'"
+ VAL="\$'${VAL//\'/\'}'"
eval "$VARNAME=$VAL"
done <"${INI_FILE}"
When I put one variable into a ini file at the end of file, it doesn't read correctly.
If script is run using "set -e" it crashes on lines 177 ((LINE_NUM++)) and 193 ((SECTIONS_NUM++))
This is because post increment returns value (defaulted at 0) before addition and set -e reads this as false, returning error.
Related stackoverflow: here
Fix is easy enough as lines can be changed to use pre-increment ((++LINE_NUM)) and ((++SECTIONS_NUM))
Bug: LINE_NUM incrementation throws an "exception" when run in bash that ships with Ubuntu 12.04.2. Error was caught when using bash 'trap' mechanism to do exception handling.
Proposed solution: change ((LINE_NUM++)) to LINE_NUM=$(($LINE_NUM + 1))
I want use bash_ini_parser on Embedded Distribution, so What's License of these?
subject changed by Rudi to match the feature request of post #2
First off: this is excellent and has saved me a lot of time. Thank you for making it and making it public.
I came across this issue when making the linux equivalent of an existing windows installer.
Works fine after converting the CRLF to LF. This is on Ubuntu 16.04.
My guess is that read
only looks for LF and the trailing CR is causing it to fail the section regex test.
Example INI:
[smtp]
host=example.com
port=25
authentication=true
use_tls=true
from_email[email protected]
username=ex
password=expass
Save it with CRLF line endings and read_ini setup.ini -p setup -b 0
will fail with
Error: Invalid line:
1: [smtp]
Test#5 fails on var3 and 4 with the same issue
expected was ... \ ......
generated only had one \ versus the two in the correct file.
bash -version
4.1.17(1) - release
Current patch level for Solaris 11.3 - patched up as of this date. 2 May 2016.
Sorry, no cut and past using my current VM setup running Solaris (Intel) under VBOX.
if additional info is needed I should be able to reconfigure the VM to allow data / network outside of the box.
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.