The following line:
`eval echo echo $VAR=\\$$VAR` >> $FILE
will output to a file called $FILE:
FOO=value_of_full
BAR=value_of_bar
I want to I output quotes, such as in:
FOO="value_of_full"
BAR="value_of_bar"
I have already tried using \" and "" but both did not work as I expected.
It is your
evalthat is swallowing up your quotes.You can use indirect variable referencing with bash >= 2.0 to alleviate the need for the
eval:Unfortunately, double (or triple…) dereferences arn’t supported, so you can’t do
${!!VAR}or${!${!VAR}}— you still have to resort to theevalmethod for those. But I don’t think you need that in this case.If you really do want to use
eval, then you will have to double-escape your escapes, like this:Or, if you really need the extra level of execution (as in your example above), then you need to triple-escape your escapes!
Personally, I prefer the 1st method 🙂