Why does sh not find files in my path that do exist?

10,198

PATH is an environmental variable in Linux and other Unix-like operating systems that tells the shell which directories to search for executable files (i.e., ready-to-run programs) in response to commands issued by a user.

To see the value of PATH variable, do it as echo $PATH. In your case, sh will look for executable in /bin and /usr/bin directory.

Also, you can use your sh commands as /bin/command if the executable of command is in the /bin directory. For example, instead of using ls you can use /bin/ls since writing ls runs the executable ls present in /bin. If the ls is not there in /bin, then it will look in /usr/bin. If ls is still not found in both the directory, then it will complain.

Trying to use $PATH or /bin:/usr/bin: directly, sh thinks that it is supposed to run bin executable located in the directory /bin:/usr/. This is the reason, it give directory or file not found or not found error.

For detailed info on PATH.

Share:
10,198

Related videos on Youtube

dv4RqQUh
Author by

dv4RqQUh

Updated on September 18, 2022

Comments

  • dv4RqQUh
    dv4RqQUh over 1 year

    When I type this in sh it outputs :

    $ $PATH
    sh: 12: /bin:/usr/bin: not found
    

    But, I do have a /usr/bin folder, and it's fuuuuull of stuff.

    Same thing with zsh:

    ▶ $PATH
    zsh: no such file or directory: /bin:/usr/bin
    

    What the hell ? How do I fix this ?

    • Admin
      Admin almost 9 years
      What command are you trying to run? Are you trying to find a command that is in your path?
    • Admin
      Admin almost 9 years
      @DavidPostill I thinks he is directly writing $PATH and executing it.
    • Admin
      Admin almost 9 years
      @RakholiyaJenish Yes, that is clear. But why is he doing that? What's he really tryng to do?
    • Admin
      Admin almost 9 years
      I think you are trying to run echo $PATH?
  • dv4RqQUh
    dv4RqQUh almost 9 years
    So, when I run this : ▶ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin‌​:/usr/games:/usr/loc‌​al/games:/media/HDD/‌​Code/android-sdk-lin‌​ux/plateform-tools:/‌​media/HDD/Code/andro‌​id-sdk-linux/tools They are no more errors, and none in sh
  • Rakholiya Jenish
    Rakholiya Jenish almost 9 years
    @N07070 Thats because, PATH is an environmental variable, which you are printing using $PATH. Hence, there won't be any error.