1

All the questions and answers i already read are not my solution. So, all i want to do is to replace the special char ' in bash.

This works:

A="abc"
B="${A//[b]/x}"

But this does not work:

A="a'b"
B="${A//[']/\'}"

Also, i have tried:

B="${A//[']/\\'}"
B="${A//[']/\\\'}"
B="${A//[']/\'''}"
B="${A//[']/'\\''}"

But B keeps to be a'b.

1 Answer 1

2

This way works:

A="a'b"
B="${A//\'/\\\'}"

Two notes:

  1. The [] are unnecessary when only one character is inside of them
  2. You need to escape \ and ' inside of the substitution.
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .