INI file format is generally composed of sections, keys, values of three parts
Format:
[Section I.]
First key = value
Second key = second value
[Section II]
First key = Val1,val2,val3
Example:
Copy Code code as follows:
In fact, this role is not so special, but multiple shell if each configuration information is written in the shell file, understand the people are OK, half understand + not careful how to change, to change a few local estimate script can not run. So it's better to be alone, and it can be configured with multiple shells using an INI file (regardless of the extension). You just need to add a custom function to the shell.
Copy Code code as follows:
# __readini [Profile path + name] [node naming] [key value]
function __readini () {
inifile=$1; section=$2; Item=$3
_readini= ' awk-f ' = '/\[' $SECTION ' \]/{a=1}a==1&&$1~/' $ITEM '/{print $2;exit} ' $INIFILE '
Echo ${_readini}
}
How to use:
Copy Code code as follows:
__readini File.ini Section KEY
Example: There is an INI format file Kinggoo.ini, which reads as follows
Copy Code code as follows:
[IP]
IP = jb51.net
[Maillist]
Mail = admin@jb51.net
Script File Contents:
Copy Code code as follows:
#!/bin/bash
# __readini [Profile path + name] [node naming] [key value]
function __readini () {
inifile=$1; section=$2; Item=$3
_readini= ' awk-f ' = '/\[' $SECTION ' \]/{a=1}a==1&&$1~/' $ITEM '/{print $2;exit} ' $INIFILE '
Echo ${_readini}
}
# Use Method:
# Net Address
_ip= ($ (__readini kinggoo.ini IP))
Echo ${_ip}
# Mail Send
_maillist= ($ (__readini kinggoo.ini maillist Mail))
Echo ${_maillist}
The Execute script file can either
When you use it, verify that you use it later.