Reputation: 57
I am echoing a string and directing it to a text file and in echoed string I need variable substitution which needs to encoded in double-quotes tried a couple of ways but unable to get it.
PASSWORD = XYZ
echo 'password =' \"'"$PASSWORD"'\" > form.txt
cat form.txt
password ='XYZ' # what I am getting
password ="XYZ" # what I am needed
Upvotes: 1
Views: 536
Reputation: 23
You can just escape "
where you need them to be evaluated as char
and omit spaces:
PASSWORD=XYZ
echo 'password ='\""$PASSWORD"\" > form.txt
Upvotes: 2
Reputation: 3499
There are different ways. One can be
PASSWORD=XYZ
echo "password=\"$PASSWORD\"" > form.txt
P.S. Of course, you know that storing password in file is usually a bad idea...
Upvotes: 3