You've already forked bash-ini-parser
mirror of
https://github.com/albfan/bash-ini-parser.git
synced 2025-11-24 23:21:07 +03:00
better documentation
This commit is contained in:
25
scripts/example.sh
Executable file
25
scripts/example.sh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ../bash-ini-parser
|
||||
|
||||
TEST_FILE="file.ini"
|
||||
# parse the config file called 'myfile.ini'
|
||||
cfg_parser "$TEST_FILE"
|
||||
|
||||
# show parsed ini file
|
||||
echo show file parsed
|
||||
cfg_writer
|
||||
echo
|
||||
|
||||
echo show some results
|
||||
# enable section called 'sec2' (in the file [sec2]) for reading
|
||||
cfg.section.sec2
|
||||
|
||||
# read the content of the variable called 'var2' (in the file
|
||||
# var2=XXX). If your var2 is an array, then you can use
|
||||
# ${var[index]}
|
||||
echo "var2 value is \"$var2\""
|
||||
echo "var5[1] value is \"${var5[1]}"\"
|
||||
echo "var5[*] value is \"${var5[*]}"\"
|
||||
echo "var4 value is \"$var4"\"
|
||||
|
||||
17
scripts/file.ini
Normal file
17
scripts/file.ini
Normal file
@@ -0,0 +1,17 @@
|
||||
;seccion one: clean whitespace
|
||||
[sec1]
|
||||
var1=foo
|
||||
var2 =hoge
|
||||
var3 = fuga
|
||||
var4= pivo
|
||||
[sec2]
|
||||
;this is the variable we want
|
||||
var1=bar
|
||||
var2=foo
|
||||
var3=eco
|
||||
;this is a multiword value
|
||||
var4="piyo baz qux"
|
||||
;this is an array
|
||||
var5=foo bar baz hoge
|
||||
var6=hoge
|
||||
|
||||
22
scripts/getkeyfromsection.sh
Executable file
22
scripts/getkeyfromsection.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ../bash-ini-parser
|
||||
|
||||
TEST_FILE="$1"
|
||||
TEST_SECTION="$2"
|
||||
TEST_VALUE="$3"
|
||||
|
||||
# parse the config file
|
||||
cfg_parser "$TEST_FILE"
|
||||
|
||||
# show parsed ini file
|
||||
echo show parsed $TEST_FILE
|
||||
cfg_writer
|
||||
echo
|
||||
|
||||
# enable section selected
|
||||
cfg.section.$TEST_SECTION
|
||||
|
||||
# show value of section selected
|
||||
echo "$TEST_VALUE value is \"${!TEST_VALUE}\""
|
||||
|
||||
Reference in New Issue
Block a user