Monday, October 12, 2015

How to read key/values pairs from text file in shell script

You can read variable values from text file which are stored in key/value format inside your shell script using following command

myKeyValuePairs.txt

 key1=Hello  
 key2=World  


Sample shell script

 while read -r line; do declare $line; done < myKeyValuePairs.txt  
 echo $key1  
 echo $key2  


Output:

 Hello  
 World  

No comments:

Post a Comment