I have a properties file with below values:
value1=one
value2=two
value3=three
flag=true
Currently my code loops through them and exports the data
for var in `grep -v '#' $properties_file| grep '=' |cut -d '=' -f 1`; do
export $var;
I want to override the value of value3 to five which I get from another file updateValue.properties if flag is set to true in my current properties file and then export it as $var with the others. How do I go about it?
updateValue.properties has value:
value3=five
Thanks!
I have a properties file with below values:
value1=one
value2=two
value3=three
flag=true
Currently my code loops through them and exports the data
for var in `grep -v '#' $properties_file| grep '=' |cut -d '=' -f 1`; do
export $var;
I want to override the value of value3 to five which I get from another file updateValue.properties if flag is set to true in my current properties file and then export it as $var with the others. How do I go about it?
updateValue.properties has value:
value3=five
Thanks!
Share Improve this question asked Feb 18 at 3:58 CleanSockCleanSock 3832 gold badges4 silver badges15 bronze badges 1- Maybe you could find a way at bash background process modify global variable – F. Hauri - Give Up GitHub Commented 2 days ago
2 Answers
Reset to default 0Use source
:
$ cat vars
var1=1
var2=2
var3=3
$ source vars
$ echo $var1 $var2 $var3
1 2 3
$ cat override
var2=5
$ source override
$ echo $var1 $var2 $var3
1 5 3
Assuming that your file stores the name of the variable:
value3=$(cat file_with_contennt_for_this_variable)
Be careful, in that this would put the whole content of the file into your variable, including empty lines etc.