Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
ssh bobby@tony:~$ which tmux                                                                        
/usr/bin/tmux
ssh bobby@tony:~$ sudo which tmux                                                                   
/usr/local/bin/tmux
ssh bobby@tony:~$ echo $PATH                                                                        
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/local/sbin:/usr/local/sbin
ssh bobby@tony:~$ sudo echo $PATH                                                                   
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/local/sbin:/usr/local/sbin

Anyone knows what's going on here? Why does sudo which tmux return /usr/local/bin/tmux instead of /usr/bin/tmux?

PS: I have 2 versions of tmux installed (one in /usr/bin and the other in /usr/local/bin).

share|improve this question
add comment

1 Answer

up vote 11 down vote accepted

It's because your root user has a different path.

sudo echo $PATH

prints your path. It's your shell that does the variable expansion, before sudo starts (and passes it as a command line argument, expanded).

Try:

sudo sh -c 'echo $PATH'
share|improve this answer
    
Precisely. It's controlled by the secure_path sudoers option. –  James Youngman Feb 26 '12 at 23:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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