How do I grab an INI value within a shell script?

Stephen Watkins picture Stephen Watkins · Jun 12, 2011 · Viewed 103.1k times · Source

I have a parameters.ini file, such as:

[parameters.ini]
    database_user    = user
    database_version = 20110611142248

I want to read in and use the database version specified in the parameters.ini file from within a bash shell script so I can process it.

#!/bin/sh    
# Need to get database version from parameters.ini file to use in script    
php app/console doctrine:migrations:migrate $DATABASE_VERSION

How would I do this?

Answer

Ali Lown picture Ali Lown · Jun 12, 2011

How about grepping for that line then using awk

version=$(awk -F "=" '/database_version/ {print $2}' parameters.ini)