Replacing line with unescaped text
I'm struggling to find a solution to this problem. I want the script below to output foo="\${var}/test" but it outputs foo="${var}/test". It seems sed (or shell) unescapes $prop and removes the backslash in front of ${var}/test.
The value of prop is fixed meaning it can't be double slashed.
I don't want to use awk, only sed.
Am I missing something obvious?
This script is just a trimmed down version of what my script really does to show the problem I'm trying to solve.
#!/bin/bash
prop='foo="\${var}/test"'
prop_name="${prop%%=*}"
echo $prop # Outputs correctly
echo 'foo="should-get-replaced"' | sed 's|^[ \t]*'"$prop_name"'[ \t]*=.*$|'"$prop"'|'
# Outputs: foo="${var}/test"
# Needs to Output: foo="\${var}/test"
|