This is the answer to Front Loading Commands
The bash shell maintains a table of commands you have used so that it can execute them more quickly without looking them up in $PATH. You can see the current list and the number of times you have used the command just by typing "hash".
If you type "ls", the shell remembers where it found it, and won't look in $PATH again until you reset $PATH or you explicitly type "hash -r". So, if this administrator probably did something like this:
# PATH=/specialstuff:$PATH # ls # cp mynewls /specialstuff/ls
The first command reset the hash table. However, he then ran "ls" - he probably forgot what he called his version and needed to see it before he could give the right copy command. The hash was reset by setting $PATH, so bash had to search each directory again to find "ls", but since there was not yet any "ls" in /specialstuff, bash found the system /bin/ls again. Bash put /bin/ls into its hash table so that it wouldn't have to search $PATH yet again. The cp put ls into /specialstuff, but nothing told bash to update its hash, so as far as it was concerned, the version in /bin was still the right one to use. The "which" command looks through $PATH, but doesn't look in the hash table (it probably should), so it confused things even more.
Got something to add? Send me email.
More Articles by Tony Lawrence © 2009-11-07 Tony Lawrence