${variable//search/replace}
SH-2001Consider using parameter expansion to search and replace data.
In the problematic code
the value is passed to sed
to do this, but for simple substitutions, parameter expansion can do it with less overhead.
string="stirng" ; echo "$string" | sed -e "s/ir/ri/"
string="stirng" ; echo "${string//ir/ri}"
Occasionally a more complex sed substitution is required. For example, getting the last character of a string.
string="stirng" ; echo "$string" | sed -e "s/^.*\(.\)$/\1/"
Utilizing some of the more complex capabilities of sed
is required occasionally and it is safe to ignore this issue.