I have a text configuration file something like this:
## COMMENT KEY1=VALUE1 ## COMMENT KEY2=VALUE2 KEY3=VALUE3 ## COMMENT ## COMMENT
As you can see, this one has key value pairs, however it also contains comment lines and empty lines. In some cases, comments are on the same line as a pair of key values.
How to read this configuration file and set the keys as variable names in a shell script so that I can use them like:
echo $KEY1
only
source config.file
then you can use these variables in your shell.
Just enter the code at the beginning of your code:
. file
or
source file
For example, here is the contents of your configuration file:
email=test@test.com user=test password=test
There are two ways:
Use the source to do this.
source $<your_file_path> echo $email
read the contents and then scroll through each line to compare to determine the correct line
cat $<your_file_path> | while read line do if [[$line == *"email"*]]; then IFS='-' read -a myarray <<< "$line" email=${myarray[1]} echo $email fi done
The second drawback of the solution is what you need to use to check each line.
Source: https://habr.com/ru/post/1502078/More articles:C # how to stop a thread in time? - multithreadingPHPUnit: Mocking a method that takes a parameter - phpDevelop Xbox Applications Using C # and Visual Studio - c #How to write a script that does "Save for the Internet" for multiple resolutions in Adobe Illustrator? - adobe-illustratorhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1502077/container-in-bootstrap-3-that-perfectly-adapts-to-the-height-of-the-viewers-screen-size&usg=ALkJrhhJKicVp51sstXjH0ZaBJtiAixK3gWhat is the correct way to specify the version of Ruby in a Rails application using the RVM to be deployed to Heroku? - ruby ββ| fooobar.compython decorator parameter using a variable from its wrapping function - pythonTree traversal using jQuery - jsonMobile jQuery theme not working - jqueryWriting WebWorker in Dart (no dart: isolate) - javascriptAll Articles