0

I don't understand why some bash commands needs a explicit path and some not.

is there somewhere a complete list of commands that needs a explicit path?

example working:

chmod +x 2copyQ.tmp.sh ; 
./2copyQ.tmp.sh ;

that's working or it says No such file or directory

example not working:

chmod +x 2copyQ.tmp.sh ; 
2copyQ.tmp.sh ;
2copyQ.tmp.sh: command not found
1

1 Answer 1

3

is there somewhere a complete list of commands that needs a explicit path?

short answer : there is no such list.

long answer :

in most interactive shell, commands are search using $PATH variable. PATH is a list of colon separated directories to look for executable.

a sample PATH looks like

 /home/archemar/bin:/usr/local/bin:/usr/sbin:/usr/bin

(actual PATH are much longer)

when you issue command foo,

  1. shell will search from left to right for an executable file named foo in directories listed in PATH, silently ignoring non exitent dir.
  2. if an executable foo is found, the shell will run it.
  3. if none is found, you'll get foo: command not found error.

If you use relative (game1/foo, ./foo) or absolute filename (/opt/tomcat/bin/start.sh ), shell will look for that file and execute it (or complain if not found).

If you want shell to find executable in current directory, just add . (local dir) in PATH, for instance

.:/home/archemar/bin:/usr/local/bin:/usr/sbin:/usr/bin

Note that adding . in PATH is considered as a bad practice for security reasons.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .