Problem with using a sed to add escape character \ before $ and ' symbols

Hi all,
I've got a problem with sed. Want to use it to add escape character \ before $ and ' symbols so

condition='1'$some will become condition=\'1\'\$some

echo "condition='1'$some" | sed 's/\($\)/\\\1/g'

is not working properly. Can somebody help me with this please?

Regards, Johny

$> cat infile
condition='1'$some
$> sed "s/['\$]/\\\&/g" infile
condition=\'1\'\$some

Thanks, much better but one problem: it cuts the end of string:

echo "cond='1'$some" | sed "s/['\$]/\\\&/g"

result
cond=\'1\'

Its because the variable $some gets expanded. Escape the $ in the echo statement and try.

I think that the problem comes from the echo statement.
The string to display is between ", the shell expands the variable $some which may be not defined.

not actual

What is the argument you pass to the script above..?

not actual. Remove the post