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

What is happening here?

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

1 Answer 1


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

You must log in to answer this question.

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