I am a bit confused about when PATH is searched. I had thought that PATH was only searched when a simple filename is given as the first token on a line, as in
$ date
A question I am solving however, seems to suggest that PATH is also searched when I very explicitly list a file with the ./ prefix:
$ ./date
Is this indeed the case? That is, if in my working directory I do not have an executable named date (say date was merely a script), the answer to this question seems to suggest that the shell will then go on to search PATH (and then find the standard date utility in some directory like bin).
I asked a somewhat analogous question here and the order for the shell search was nicely given in answer there. However, there I emphasized that I was simply giving the command as a simple filename. Here, I am very explicitly giving a ./ prefix. Why does the shell still search PATH, or am I missing something?
From Sobell's A Practical Guide to Linux:
Explain the following unexpected result:
$ whereis date
date: /bin/date ...
$ echo $PATH
.:/usr/local/bin:/usr/bin:/bin
$ cat > date
echo "This is my own version of date."
$ ./date
Sun May 21 11:45:49 PDT 2017
One "expects" that the shell script ./date is run so that the output is "This is my own version of date."
PATHwhen given./date? What's the evidence for that?$ dateas the command in the final line? @muru