sed is not working in a bash script when a variable is used in the same copycat

An interesting fact about sed is, characters other than ‘/’ can be used as the separator.


Your code would result in


The first thing to note is that the last quote and the separator are the wrong way round. But you don’t want to add single quotes to the variable. The error can be recreated like this:

echo "userDir:abc" | sed "'s|userDir:abc|userDir:xyz|'"

If you remove the single quotes it will work.


The extra quotes are unnecessary and can also be removed:


CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top