Hello everyone! I have the task to remove first pattern match from string. Now my code is:
It works properly for cases without
Bash:
#!/bin/bash
function removeFirstMatch()
{
local string="$1"
local pattern="$2"
left=${string%%$pattern*}
right=${string#*$pattern}
echo "$left$right"
}
echo $(removeFirstMatch 'a\b\c' '\') # I want to obtain ab\c but actually get a\b\ca\b\c.
\
but I want it work normally everywhere.