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

The name of the pictureThe name of the pictureThe name of the pictureClash 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.










share|improve this question









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.























    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.










    share|improve this question









    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.





















      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.










      share|improve this question









      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






      share|improve this question









      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.











      share|improve this question









      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.









      share|improve this question




      share|improve this question








      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.




















          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)






          share|improve this answer




















          • 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










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Jon Kennedy is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          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






























          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)






          share|improve this answer




















          • 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














          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)






          share|improve this answer




















          • 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












          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)






          share|improve this answer












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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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
















          • 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










          Jon Kennedy is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          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.













           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)