0

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 ?

1
  • Cannot reproduce. Which *nix variant - or which GNU/Linux distribution - are you using? Commented Sep 28, 2018 at 15:27

2 Answers 2

1

If 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 root has /usr/bin/ before /bin (or without /bin at all).

You can verify this by running:

echo ${PATH}

as both root and the non-root user.

The 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.

0

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

PATH="/usr/bin:/bin:... 

and for the user it should be something like

 PATH="/bin...

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.