1

If I run sudo which abc I would expect it to search the superusers $PATH for the program 'abc', but it looks like it only searches a subset.

I can see this by running sudo echo $PATH and comparing the paths searched.

$ sudo which abc
which: no abc in (/sbin:/bin:/usr/sbin:/usr/bin)

$ sudo echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin

What is happening here?

  • And where is abc actually located ? – steve Jul 28 '18 at 10:50
  • 2
    Note that sudo echo $PATH will not show root's $PATH. gets resolved by current she'll and then passed to sudo.... – steve Jul 28 '18 at 10:52
  • 1
    Also note that if you use sudo to actually execute abc, it is typically configured to search its own secure_path rather than the root user's PATH. See man sudoers. – steeldriver Jul 28 '18 at 11:25
4

$PATH is expanded before sudo is run. Therefore you are seeing the value of PATH for you, and not for the user you sudo to.

try this instead:

$ sudo bash -c 'echo $PATH'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.