I have a shell script that uses base64 to encode a value and store it in a variable.
encoded="$(cat $pathtofile|base64 -w 0)"
This worked until I ended up with a $pathtofile
that had a special character in it. Now I'm trying to figure out how to quote the $pathtofile
so that cat gets the right file. When I do this
encoded="$(cat '$pathtofile'|base64 -w 0)"
I end up with an error because it doesn't expand $pathtofile
, but prints it literally. I have tried several other combinations, but they all result in a misquoted path.
How can I end up with a quoted $pathtofile
?