How do I get value of variable from file using shell script?

前端 未结 4 1060
隐瞒了意图╮
隐瞒了意图╮ 2021-01-15 05:41

There is a file post_check.ini I need the value set for:

Max_value=2

How would I get the value 2 from Max_v

4条回答
  •  生来不讨喜
    2021-01-15 05:59

    You might find it useful to use proper config file parser. Given the following .ini file:

    $ cat post_check.ini
    [section 1]
    Max_value=123
    [section 2]
    Max_value=456
    

    The following python script will print 123:

    import ConfigParser, os
    config = ConfigParser.ConfigParser()
    config.read('post_check.ini')
    print config.get('section 1','Max_value')
    

    This is most reliable and modifiable way to go if you need to work with config files.

提交回复
热议问题