2

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.

0

1 Answer 1

5

./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)

4
  • Such a simple nuance, I am embarrassed I did not notice that. Thank you! Commented Nov 13, 2018 at 16:06
  • You're welcome! If this solved your problem, please accept the answer. Commented Nov 13, 2018 at 16:22
  • 1
    To put a finer point on it: An absolute path starts with /; anything else will be a relative path. Commented Nov 13, 2018 at 18:16
  • @panki, sort I was at work all day and this is the first chance I have had to accept it. Commented Nov 14, 2018 at 2:03

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.