I'm just trying to understand how it actually works, because for example, in Terminal if a path contains spaces, we need to either put the path inside double quotes or we have to escape the spaces, right?
Now, with a semi-good night sleep, I was able to sit down and perform a few more tests and some things are a bit clearer, for example, I thought that when we use $KMVAR we always need the double quotes, no matter what, even if the path does not have any spaces. From my tests I noticed that this is not the case. I tried 4 different versions:
1 - Path WITH spaces, your ls
script WITH quotes → no error
2 - Path WITH spaces, your ls
script WITHOUT quotes → ERROR
1 - Path WITHOUT spaces, your ls
script WITH quotes → no error
2 - Path WITHOUT spaces, your ls
script WITHOUT quotes → no error
So this showed me that the double quotes around $KMVAR is just for paths with spaces. I think using quotes as a habit is more of a way to prevent potential errors, so if we always use double quotes, we are always including both options, no matter what.
What I noticed last night was that when I tried the echo
option and I included the quotes, the displayed result would show me without quotes. That made me assume that the script would read it without quotes, throwing an error, because of what I just said at the top about using quotes OR escaping the spaces.
Another thing I noticed / learned from my tests today is that $KMVAR always needs the underscores when there's spaces in the variable. I wrongly thought that what I had in the script should be exactly the same as the variable itself, which is not the case. What I mean is that I can still have variables with spaces such as Local__Video Path
, but then the script needs to be $KMVAR_Local__Video_Path
. I thought I needed to actually rename the variables to Local__Video_Path
as well in order for it to work, but no need to. Only the $KMVAR needs the underscores. I got that info from here
So I just performed a final test and it works! 
I guess the issue here was really what echo
was showing me. It removes the quotes around the paths, making me think that the script would fail. Let me show you what I got:

You can see that I have the quotes around all KMVAR
instances.
Then my prompt:

And now the window where you can see that the quotes are gone:

This made me think that it would throw an error, that's why I was adding the "\"
and all that. If I copied this result window script and pasted it in Terminal, it would fail, hence the escaped quotes. Hope it makes sense what I'm trying to explain?
Thank you for your help!
One question: is there a way to use echo
but where I can see the actual script including the quotes around paths? I mean, now I know that in this particular case the paths are good to go if I use the quotes around $KMVAR, but for other scripts I would like to see the script as is, to avoid confusion.