I am having a problem with this.
If I do...
source /Users/cristian/Proyectos/MikroTik\ Updater/sources/testfile
It does work
If I do...
source "/Users/cristian/Proyectos/MikroTik\ Updater/sources/testfile"
It doesn’t
The problem is that I’m using a variable which contains a path got some steps before
So this...
mypath="/Users/cristian/Proyectos/MikroTik\ Updater/sources/testfile"
source $mypath
Doesn’t work neither
I found a workaround doin...
eval "source $mypath"
But of course it is a big security hole because file name comes from an argument
What can I do?
EDIT:
As you can see in the code I echo the filename and then try to source it
updaterpath="$( cd "$(dirname "$0")" ; pwd -P | sed 's/ /\\ /g' )"
sourcefile="$updaterpath/sources/$1"
echo $sourcefile
source $sourcefile
In the output I get the correct path echoed and the error from source saying it doesn't exists! The funny thing is that whether I cat that file, I can see the content, so the file path is correct!
/Users/cristian/Proyectos/MikroTik\ Updater/sources/testfile
/Users/cristian/Proyectos/MikroTik Updater/updater.sh: line 7: /Users/cristian/Proyectos/MikroTik\: No such file or directory
“instead of ascii quotes"source /path/to/fileandsource "/path/to/file"; the quotes are removed by the shell beforesourceis executed.sedto escape a path.$0is unreliable for finding your script location.