Illustrated in this console session
bir@N2C:~$ echo $PATH
.../home/bir/bin:... # script folder is in PATH
bir@N2C:~$ ls -lh ~/bin/ # script permissio
There is usually a test in /usr/bin/test, which would be ahead of the one in your home directory in your path. You can figure this out by entering the command which test
EDIT: As Alok Singhal points out in a comment below, test
is also one of the commands built into the bash shell (and some other shells), and if you are using bash, then another built-in shell command, type
, can show you, not only which test
will be executed (even if it is a shell built-in and not available on the file system), but also, all the versions of test it is hiding. For example, if I have /home/pat/bin ahead of /usr/bin:
$ type -a test
test is a shell builtin
test is /home/pat/bin/test
test is /usr/bin/test
So, typing type -a <cmdname>
is very useful to figure out, not only what will be executed, but also what will not be executed. By showing full paths, it also lets you use cut and paste (in most terminal programs) to choose and execute the proper program, even if you decide not to rename it. (Other shells also have similar alias facilities.)
As an aside, man type
won't give you any useful information about the type
bash shell command, because it's not a standalone program. man bash
does describe it, since it is built in to the bash shell -- but there are a lot of uses of the literal word "type" in that document, so it's quickest to scroll to the bottom if you are looking for information on the type
command.
EDIT2: As hek2mgl points out, the hash command also be useful if you are having trouble getting your command to execute. In particular, if you have created a program that has the same name as something else, and you have already run that something else, your script may not run, even though it's first in the path:
$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ echo echo Hi there! > bin/python
$ chmod 700 bin/python
$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ hash -r # Clear the hash for this instance of bash
$ python
Hi there!
$ rm bin/python
$ python
bash: /home/pat/bin/python: No such file or directory
$ hash -r
$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>