I have a file:
/Users/danylo.volokh/test/test_bash_script.sh
Content is very simple:
#!/usr/bin/env bash
echo "-- print from script"
I'm in folder "danylo.volokh"
This command runs fine:
Danilos-MacBook-Pro:~ danylo.volokh$ test/test_bash_script.sh
-- print from script
But if I try to run in with absolute path I get an error:
Danilos-MacBook-Pro:~ danylo.volokh$ /test/test_bash_script.sh
-bash: /test/test_bash_script.sh: No such file or directory
I want to run a command with absolute path from any folder and get the script to be executed.
Best Answer
I want to run a command with absolute path from any folder and get the script to be executed.
File
/test/test_bash_script.sh
does not exist, and so cannot be executed.An absolute path is defined as the specifying the location of a file or directory from the root directory (
/
)./test
cannot be an absolute path as the directory/test
does not exist (it is a subdirectory of your home directory).You have two choices:
Use the correct absolute path to the script:
Use the path based on your home directory:
What is an absolute path?
Source Absolute path vs relative path in Linux/Unix
Source Unix/Linux Pathnames (absolute, relative, dot, dot dot)