I see the script location for the command
date for a normal user, it shows
which date /bin/date
But when I run the same command from root it shows the output
/usr/bin/date. Why so ?
which date produces different results for
root and another user, then it's likely that they have different values for
PATH. The normal user has
/bin earlier than
/usr/bin (or without
/usr/bin at all) and
/bin (or without
/bin at all).
You can verify this by running:
root and the non-root user.
PATH variable is a colon-delimited list of directories in which the shell looks for commands when the absolute path isn't provided. The shell will search those directories, left to right, in the order that they're listed. If the shell finds a command in a directory, then it executes it. The
which command does a similar walk and reports the first match that it finds.
It depends on the
$PATH variable of the user you are currently logged in. If the script is on more than one directories the first found is used, in this case
$PATH of root should be something like
and for the user it should be something like