INI file format is generally composed of section, key, value three parts
Format:
[first section ]
First key = value
Second key = second value
[section II ]
First key = Val1,val2,val3
Example:
[COM]
Kinggoo = kinggoo.com
In fact, this role is not so particularly large, but multiple shells if each configuration information in the shell file is written, understand the person is OK, half understand + not careful how people want to change, several places to estimate the script can not run. So it's better to be alone, and multiple shells can be configured with an INI file (regardless of the extension). Just add a custom function to the shell.
# __readini [config file path + name] [node name] [key value]function __readini () {inifile= $; section=$2;item='/\['$SECTION' \]/{a=1}a==1&&$1~/'$ITEM$INIFILE '${_readini }}
How to use:
__readini File.ini Section KEY
Example: There is an INI format file Kinggoo.ini, the content is as follows
[IP] kinggoo.com[maillist][email protected]
Script File Contents:
#!/bin/bash# __readini [Profile path + name] [node name] [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: # Net address_ip= ($ (__ Readini kinggoo.ini IP IP)) echo ${_ip}# Mail send _maillist= ($ (__readini kinggoo.ini maillist Mail)) echo ${_maillist}
Executing a script file can either
When using it yourself, please use it after verification.
- This article is from: Linux Learning Tutorial Network
Shell reads INI format file to make configuration file