1

While working with Config files (user defined variables in file) I need below requirement. I have variables in config files and need to read variables from files and order of precedence. Example as given below

Main parameter (default) file.

    param.ini: 
    Var1=today
    Var3=xyz

Override parameter file (adhoc override changes)

    Param.override:
    var1=yesterday
    var2=123

My script as given below

    test.sh:
    . ~/param.override,~/param.ini

    echo "run day -> $var1"

Result i need is

    run day -> yesterday

I remember we can achieve this using dot operator or Source command in Unix. Please help me what will be syntax for script to call variable from multiple files.

zero298
  • 25,467
  • 10
  • 75
  • 100
Unixhelp
  • 13
  • 3
  • Does [this](https://stackoverflow.com/questions/9772036/pass-all-variables-from-one-shellscript-to-another) help? – mathB Oct 09 '17 at 16:56
  • Unfortunately No!! as my requirement is more than one file has variable with the same name I need to control that value from config file not in the script. Thanks for looking into it. – Unixhelp Oct 09 '17 at 20:46

1 Answers1

0

This: works for me, not sure if you tried this?

$ cat param.ini
Var1=today
Var3=xyz

$ cat param.override
Var1=yesterday
var2=123

$ cat test.sh
#!/usr/bin/bash
. ~/cygwin/param.override ~/cygwin/param.ini

echo "run day -> $Var1"

$ ./test.sh
run day -> yesterday
mathB
  • 634
  • 8
  • 21