Answer the question
In order to leave comments, you need to log in
How to substitute in a string taken from a file the value of a variable set in the script in a bash script?
There is an example.txt file, which contains lines like:
# Comment 1
$VAR1/teststring1
# Comment 2
$VAR2/teststring2
#!/bin/bash
VAR1="hello"
VAR2="world"
STRING=`awk '!/^\ *#/&&(length > 0), ORS=" "' example.txt`
echo $STRING
Answer the question
In order to leave comments, you need to log in
If vlob then the dumbest option that comes to mind is to replace the last line with
echo $STRING | sed -e 's/\$VAR1/'$VAR1'/g' -e 's/\$VAR2/'$VAR2'/g'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question