Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

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?

1 Answer

0 votes
by (50.2k points)

Use the below command using awk 

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

As per your question, this single liner will grab your ini value within the shell script 

This is useful for basic INI files, if it has 2 [parameters.ini] this will return the value twice

And to remove that we can use specialized ini parser like crudini.

Related questions

Browse Categories

...