Shell reads INI format file to make configuration file

Source: Internet
Author: User
Tags shebang

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.