Skip to main content
Removed code highlighting since it was screwing with the syntax
Source Link
terdon
  • 252.3k
  • 69
  • 480
  • 718

You could use variable substitution:

$ OUTPUT=a\'b\"c\`d
$ echo "$OUTPUT"
a'b"c`d

Use that syntax: ${parameter//pattern/string} to replace all occurrences of the pattern with the string.

$ echo "${OUTPUT//\'/x}"
axb"c`d
$ echo "${OUTPUT//\"/x}"
a'bxc`d
$ echo "${OUTPUT//\`/x}"
a'b"cxd
$ echo "${OUTPUT//[\'\"\`]/x}"
axbxcxd
$ echo "${OUTPUT//\'/x}"
axb"c`d
$ echo "${OUTPUT//\"/x}"
a'bxc`d
$ echo "${OUTPUT//\`/x}"
a'b"cxd
$ echo "${OUTPUT//[\'\"\`]/x}"
axbxcxd

You could use variable substitution:

$ OUTPUT=a\'b\"c\`d
$ echo "$OUTPUT"
a'b"c`d

Use that syntax: ${parameter//pattern/string} to replace all occurrences of the pattern with the string.

$ echo "${OUTPUT//\'/x}"
axb"c`d
$ echo "${OUTPUT//\"/x}"
a'bxc`d
$ echo "${OUTPUT//\`/x}"
a'b"cxd
$ echo "${OUTPUT//[\'\"\`]/x}"
axbxcxd

You could use variable substitution:

$ OUTPUT=a\'b\"c\`d
$ echo "$OUTPUT"
a'b"c`d

Use that syntax: ${parameter//pattern/string} to replace all occurrences of the pattern with the string.

$ echo "${OUTPUT//\'/x}"
axb"c`d
$ echo "${OUTPUT//\"/x}"
a'bxc`d
$ echo "${OUTPUT//\`/x}"
a'b"cxd
$ echo "${OUTPUT//[\'\"\`]/x}"
axbxcxd
replacing all occurrences was requested
Source Link
Gilles 'SO- stop being evil'
  • 865.5k
  • 205
  • 1.8k
  • 2.3k

You could use variable substitution:

$ OUTPUT=a\'b\"c\`d
$ echo $OUTPUT"$OUTPUT"
a'b"c`d

Use that syntax: ${parameter//pattern/string} to replace all occurrences of the pattern with the string.

$ echo $"${OUTPUT//\'/x}"
axb"c`d
$ echo $"${OUTPUT//\"/x}"
a'bxc`d
$ echo $"${OUTPUT//\`/x}"
a'b"cxd
$ echo "${OUTPUT//[\'\"\`]/x}"
axbxcxd

You could use variable substitution:

$ OUTPUT=a\'b\"c\`d
$ echo $OUTPUT
a'b"c`d

Use that syntax: ${parameter/pattern/string}

$ echo ${OUTPUT/\'/x}
axb"c`d
$ echo ${OUTPUT/\"/x}
a'bxc`d
$ echo ${OUTPUT/\`/x}
a'b"cxd

You could use variable substitution:

$ OUTPUT=a\'b\"c\`d
$ echo "$OUTPUT"
a'b"c`d

Use that syntax: ${parameter//pattern/string} to replace all occurrences of the pattern with the string.

$ echo "${OUTPUT//\'/x}"
axb"c`d
$ echo "${OUTPUT//\"/x}"
a'bxc`d
$ echo "${OUTPUT//\`/x}"
a'b"cxd
$ echo "${OUTPUT//[\'\"\`]/x}"
axbxcxd
Source Link
chaos
  • 49.3k
  • 11
  • 127
  • 147

You could use variable substitution:

$ OUTPUT=a\'b\"c\`d
$ echo $OUTPUT
a'b"c`d

Use that syntax: ${parameter/pattern/string}

$ echo ${OUTPUT/\'/x}
axb"c`d
$ echo ${OUTPUT/\"/x}
a'bxc`d
$ echo ${OUTPUT/\`/x}
a'b"cxd