Shell: using sed in backticks
I want to avoid special characters inside a string automatically. I thought about repeating this chain and blowing it through some seeds. It doesn't seem to work inside backticks. So why
echo "foo[bar]" | sed 's/\[/\\[/g'
return
foo\[bar]
but
FOO=`echo "foo[bar]" | sed 's/\[/\\[/g'` && echo $FOO
just returns
foo[bar]
?
Unlike sed, tr works great inside backticks:
FOO=`echo "foo[bar]" | tr '[' '-' ` && echo $FOO
returns
foo-bar]
+2
Nico
source
to share
3 answers