-1

I have this batch script:

#target environment (this can be DEV/QA/PROD)
targetEnv=DEV 

url=get this from file name env_prop_${DEV}.ini
user=get this from file name env_prop_${DEV}.ini
password=get this from file name env_prop_${DEV}.ini

what i would like to do is extract all the the environment configuration into seperate files like:

config_DEV.ini   containing:
         url=dev1
         user=dev1
         password=pass1
config_QA.ini   containing:
         url=qa-server
         user=dev
         password=password
config_PROD.ini   containing:
         url=prod-server-01
         user=manager007
         password=*******

And then substitute the script variables according to the targetEnv
so for example if targetEnv is QA, variable url will be

       url=qa-server
       user=dev
       password=password
JavaSheriff
  • 7,074
  • 20
  • 89
  • 159

1 Answers1

1

You can do it this way:

url=$(awk -F "=" '/url/ {print $2}' config_$targetEnv.ini)
user=$(awk -F "=" '/user/ {print $2}' config_$targetEnv.ini)
password=$(awk -F "=" '/password/ {print $2}' config_$targetEnv.ini)

Or by sourcing your .ini, if it is formatted the way you wrote:

source config_$targetEnv.ini

There is useful information here: How do I grab an INI value within a shell script?