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:
"/etc/resolve.conf" ""
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:
"/etc/resolve.conf"
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
/"/etc/resolve.conf"
in the same way a path like
folder/file.txt
would get translated in to
/folder/file.txt
So when you set $tmp to
"/etc/resolve.conf" ""
It actually passes two parameters to subl:
- "/etc/resolve.conf"
- ""
If your path had a space in it, like:
"/etc/resol ve.conf" ""
it would actually get three parameters:
- "/etc/resol
- ve.conf"
- ""
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