How can I run a bash script from an absolute path versus a relative path

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a file in my root directory called bash_scripts and within it I have a file called create_py_dir.sh. At present the only command in the shell script is pwd, which I am using just to ensure it is working correctly. The directory structure is shown below;
desktop
|
myname(i.e. root directory)
|
bash_scripts
|
create_py_dir.sh
If I cd to the same directory as the scripts and run a pwd command it tells me that the file is in the directory /Users/myname/bash_scripts. So lets say that I go back to the root directory and up one directory to the desktop via cd ../desktop and from there I run the script via relative path with ./../bash_scripts/create_py_dir.sh, the scripts works just fine. However, if I try to execute it via an absolute path with ./Users/myname/bash_scripts/create_py_dir.sh I get the following error, ./Users/myname/bash_scripts/create_py_dir.sh: No such file or directory. I think I have a fundamental understanding problem with how to run shell scripts from absolute paths.
bash shell-script
New contributor
Jon Kennedy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
I have a file in my root directory called bash_scripts and within it I have a file called create_py_dir.sh. At present the only command in the shell script is pwd, which I am using just to ensure it is working correctly. The directory structure is shown below;
desktop
|
myname(i.e. root directory)
|
bash_scripts
|
create_py_dir.sh
If I cd to the same directory as the scripts and run a pwd command it tells me that the file is in the directory /Users/myname/bash_scripts. So lets say that I go back to the root directory and up one directory to the desktop via cd ../desktop and from there I run the script via relative path with ./../bash_scripts/create_py_dir.sh, the scripts works just fine. However, if I try to execute it via an absolute path with ./Users/myname/bash_scripts/create_py_dir.sh I get the following error, ./Users/myname/bash_scripts/create_py_dir.sh: No such file or directory. I think I have a fundamental understanding problem with how to run shell scripts from absolute paths.
bash shell-script
New contributor
Jon Kennedy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a file in my root directory called bash_scripts and within it I have a file called create_py_dir.sh. At present the only command in the shell script is pwd, which I am using just to ensure it is working correctly. The directory structure is shown below;
desktop
|
myname(i.e. root directory)
|
bash_scripts
|
create_py_dir.sh
If I cd to the same directory as the scripts and run a pwd command it tells me that the file is in the directory /Users/myname/bash_scripts. So lets say that I go back to the root directory and up one directory to the desktop via cd ../desktop and from there I run the script via relative path with ./../bash_scripts/create_py_dir.sh, the scripts works just fine. However, if I try to execute it via an absolute path with ./Users/myname/bash_scripts/create_py_dir.sh I get the following error, ./Users/myname/bash_scripts/create_py_dir.sh: No such file or directory. I think I have a fundamental understanding problem with how to run shell scripts from absolute paths.
bash shell-script
New contributor
Jon Kennedy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have a file in my root directory called bash_scripts and within it I have a file called create_py_dir.sh. At present the only command in the shell script is pwd, which I am using just to ensure it is working correctly. The directory structure is shown below;
desktop
|
myname(i.e. root directory)
|
bash_scripts
|
create_py_dir.sh
If I cd to the same directory as the scripts and run a pwd command it tells me that the file is in the directory /Users/myname/bash_scripts. So lets say that I go back to the root directory and up one directory to the desktop via cd ../desktop and from there I run the script via relative path with ./../bash_scripts/create_py_dir.sh, the scripts works just fine. However, if I try to execute it via an absolute path with ./Users/myname/bash_scripts/create_py_dir.sh I get the following error, ./Users/myname/bash_scripts/create_py_dir.sh: No such file or directory. I think I have a fundamental understanding problem with how to run shell scripts from absolute paths.
bash shell-script
bash shell-script
New contributor
Jon Kennedy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Jon Kennedy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited yesterday
Rui F Ribeiro
38.1k1475123
38.1k1475123
New contributor
Jon Kennedy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked yesterday
Jon Kennedy
31
31
New contributor
Jon Kennedy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Jon Kennedy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Jon Kennedy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
./Users/myname/bash_scripts/create_py_dir.sh is not an absolute path.
A . is a reference to the current folder.
This would be an example of an absolute path:/Users/myname/bash_scripts/create_py_dir.sh
(assuming the directory Users exists in the top level of the file system)
Such a simple nuance, I am embarrassed I did not notice that. Thank you!
– Jon Kennedy
yesterday
You're welcome! If this solved your problem, please accept the answer.
– Panki
yesterday
1
To put a finer point on it: An absolute path starts with/; anything else will be a relative path.
– DopeGhoti
yesterday
@panki, sort I was at work all day and this is the first chance I have had to accept it.
– Jon Kennedy
20 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
./Users/myname/bash_scripts/create_py_dir.sh is not an absolute path.
A . is a reference to the current folder.
This would be an example of an absolute path:/Users/myname/bash_scripts/create_py_dir.sh
(assuming the directory Users exists in the top level of the file system)
Such a simple nuance, I am embarrassed I did not notice that. Thank you!
– Jon Kennedy
yesterday
You're welcome! If this solved your problem, please accept the answer.
– Panki
yesterday
1
To put a finer point on it: An absolute path starts with/; anything else will be a relative path.
– DopeGhoti
yesterday
@panki, sort I was at work all day and this is the first chance I have had to accept it.
– Jon Kennedy
20 hours ago
add a comment |
up vote
3
down vote
accepted
./Users/myname/bash_scripts/create_py_dir.sh is not an absolute path.
A . is a reference to the current folder.
This would be an example of an absolute path:/Users/myname/bash_scripts/create_py_dir.sh
(assuming the directory Users exists in the top level of the file system)
Such a simple nuance, I am embarrassed I did not notice that. Thank you!
– Jon Kennedy
yesterday
You're welcome! If this solved your problem, please accept the answer.
– Panki
yesterday
1
To put a finer point on it: An absolute path starts with/; anything else will be a relative path.
– DopeGhoti
yesterday
@panki, sort I was at work all day and this is the first chance I have had to accept it.
– Jon Kennedy
20 hours ago
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
./Users/myname/bash_scripts/create_py_dir.sh is not an absolute path.
A . is a reference to the current folder.
This would be an example of an absolute path:/Users/myname/bash_scripts/create_py_dir.sh
(assuming the directory Users exists in the top level of the file system)
./Users/myname/bash_scripts/create_py_dir.sh is not an absolute path.
A . is a reference to the current folder.
This would be an example of an absolute path:/Users/myname/bash_scripts/create_py_dir.sh
(assuming the directory Users exists in the top level of the file system)
answered yesterday
Panki
41019
41019
Such a simple nuance, I am embarrassed I did not notice that. Thank you!
– Jon Kennedy
yesterday
You're welcome! If this solved your problem, please accept the answer.
– Panki
yesterday
1
To put a finer point on it: An absolute path starts with/; anything else will be a relative path.
– DopeGhoti
yesterday
@panki, sort I was at work all day and this is the first chance I have had to accept it.
– Jon Kennedy
20 hours ago
add a comment |
Such a simple nuance, I am embarrassed I did not notice that. Thank you!
– Jon Kennedy
yesterday
You're welcome! If this solved your problem, please accept the answer.
– Panki
yesterday
1
To put a finer point on it: An absolute path starts with/; anything else will be a relative path.
– DopeGhoti
yesterday
@panki, sort I was at work all day and this is the first chance I have had to accept it.
– Jon Kennedy
20 hours ago
Such a simple nuance, I am embarrassed I did not notice that. Thank you!
– Jon Kennedy
yesterday
Such a simple nuance, I am embarrassed I did not notice that. Thank you!
– Jon Kennedy
yesterday
You're welcome! If this solved your problem, please accept the answer.
– Panki
yesterday
You're welcome! If this solved your problem, please accept the answer.
– Panki
yesterday
1
1
To put a finer point on it: An absolute path starts with
/; anything else will be a relative path.– DopeGhoti
yesterday
To put a finer point on it: An absolute path starts with
/; anything else will be a relative path.– DopeGhoti
yesterday
@panki, sort I was at work all day and this is the first chance I have had to accept it.
– Jon Kennedy
20 hours ago
@panki, sort I was at work all day and this is the first chance I have had to accept it.
– Jon Kennedy
20 hours ago
add a comment |
Jon Kennedy is a new contributor. Be nice, and check out our Code of Conduct.
Jon Kennedy is a new contributor. Be nice, and check out our Code of Conduct.
Jon Kennedy is a new contributor. Be nice, and check out our Code of Conduct.
Jon Kennedy is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481496%2fhow-can-i-run-a-bash-script-from-an-absolute-path-versus-a-relative-path%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password