How to check what command is taken?

Solution 1:

A few days ago I was satisfied with my answer. I also knew that the which command is not used to test whether a command exists. Now I'm not so satisfied with my answer, and I refer to this great response.


With a simple which command:

which foo.sh

Or a type command:

type foo.sh

And you can influence this with the order of the paths in your $PATH or via an absolute path when the script starts, E.G.

/home/user/scripts/foo.sh

Example

If PATH is defined as below

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

And you start a script or something else which is in /usr/local/bin and in /usr/bin, the script in /usr/local/bin as a higher priority.