You do not need to avoid anything in the input :
$ echo "123 ' foo & b'ar" | sed "s/'/''/g"
123 '' foo & b''ar
However, in the “replacement” of a part of a team, it s &has a special meaning: it means “compliance”. Therefore, the above command can be rewritten as follows:
$ echo "123 ' foo & b'ar" | sed "s/'/&&/g"
123 '' foo & b''ar
Select it with \, like everything else that needs to be shielded, if necessary:
$ echo "123 ' foo & b'ar" | sed "s/'/'\&'/g"
123 '&' foo & b'&'ar
source
share