I’m getting totally crazy with the following script.
The following command works as expected :
echo a | sed 's/a/b/'
Output :
b
But this script doesn’t :
test="'s/a/b/'"
echo a | sed $test
Output :
sed: -e expression #1, char 1: unknown command : `''
I should really be stupid, but I don’t see what I am missing.
Thanks,
This is because your double wrapping your string.
test="'s/a/b'". Sed then gets's/a/b/'as literal string. You only want sed to receives/a/b/.You only need to wrap the string in one set of quotes, otherwise the inner set of quotes will be interpreted as part of the argument.