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?

3
  • And where is abc actually located ?
    – steve
    Commented Jul 28, 2018 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
    Commented Jul 28, 2018 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. Commented Jul 28, 2018 at 11:25

1 Answer 1

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'
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .