I am not trying to execute a Bash script from any directory by adding the script to my Path variable.
I want to be able to execute the script from any directory using the directory path to that file ... but the file I want to execute sources other files, that is the problem.
If I am in directory file
with two scripts myFunctions.sh
and sourceFunctions.sh
sourceFunctions.sh
#!/bin/bash
source ./myFunctions.sh
echoFoo
myFunctions.sh
function echoFoo()
{
echo "foo"
}
I can run myFunctions.sh
and foo
will print to console, but If I go up a directory and run myFunctions.sh
I get error
cd ..
file/sourceFunctions.sh
-bash: doFoo.sh: command not found
Unless I changed source file/myFunctions.sh
to source file/myFunctions.sh
in sourceFunctions.sh
.
So how can I source independent of my working directory so I can run sourceFunctions.sh
from any working directory I want?
Thanks