OK, there are multiple problems.
The first is that your search and replace is adding an extra "" parameter at the end, so you are getting parameters of:
But the bigger problem is that quotes within variables are meaningless, so that when this is processed by echo or by subl, the first parameter is actually:
That is not a valid file name, and because it does not start with ~ or / and there is no meaningful working directory, that is probably why it is being translated in to
in the same way a path like
would get translated in to
So when you set $tmp to
It actually passes two parameters to subl:
If your path had a space in it, like:
"/etc/resol ve.conf" ""
it would actually get three parameters:
The quotes in the variable are meaningless, they are just plain characters by that point.
Instead you need to split the input variable into parts actively. The
xargs tool is the easiest.
Get rid of all your processing, just leave them as line separated paths, and then use something like:
echo "$KMVAR_filepath" | tr '\r\n' '\0' | xargs -0 /usr/local/bin/subl