bash script source: No such file or directory
I have a script that begin like this
#!/bin/bash
VALKYRIE=~/myProjects/valkyrie
source $VALKYRIE/cluster.conf
but when I run it it returns
line 2: ~/myProjects/valkyrie/cluster.conf: No such file or directory
but the file exist and when I run source ~/myProjects/valkyrie/cluster.conf
it runs fine.
Any idea? I set VALKYRIE
variable elsewhere so hard-code in the path isn't an option.
~
doesn't appear to be expanding properly. When I run your script with an intentionally fake path, the error doesn't say ~
, but expands the path (i.e. /home/sparhawk/fakepath
not ~/fakepath
. You could try using $HOME
instead of ~
, or using the full path in the script instead.
(I'm not sure why ~
doesn't work on your system, as your script works fine for me.)