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.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

1 Answers1

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)

Panki
  • 6,664