LoginSignup
17
16

More than 5 years have passed since last update.

bashでiniファイルを読む

Posted at
setting.ini
[product]
a=123
[test]
a=456
bash_ini_parser.sh

# ini setting
INI_FILE=sample.ini
INI_SECTION=test

# ini parser
eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
    -e 's/;.*$//' \
    -e 's/[[:space:]]*$//' \
    -e 's/^[[:space:]]*//' \
    -e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \
   < $INI_FILE \
    | sed -n -e "/^\[$INI_SECTION\]/,/^\s*\[/{/^[^;].*\=.*/p;}"`

echo $a # 456
17
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
16