I have a bash script that'll take any word passed to it as a parameter and then encrypt the word using an openssl command. From there I want to take the returned string and use sed to write it into another file. The encrypted value sometimes contains the "/" character (but not always) at which point sed fails to function.
Here's the gist of what the script looks like:
#!/bin/bash
fileDirectory"/etc/ci"
fileName="key.bin"
encryptedOSPFPW='echo $1 | openssl enc -a -A -aes-256-cbc -md sha256 -pass file:"$fileDirectory"/"$fileName"'
sed -i "s/OSPFPW/$encryptedOSPFPW/g" /etc/quagga/ospfd.conf
exit 0How can I adjust the sed command so that it'll substitute whatever is returned into literally. I know that if I replace the double-quotes with single-quotes, sed will take whatever's supplied to it literally, but that doesn't work when I'm using a variable.
Thanks
71 Answer
The answer to this question was to use a different delimiter with the sed command. I ended up using the following command:
sed -i "s|OSPFPW|$encryptedOSPFPW|g" /etc/quagga/ospfd.conf 1