New answers tagged which
command -pv uses a "default value for PATH". $ which ruby /home/mikel/.rvm/rubies/ruby-1.9.3-p484/bin/ruby $ command -pv ruby /usr/bin/ruby Unfortunately that doesn't work in zsh, so based on Stephane's comment, we could use getconf PATH: $ PATH=$(getconf PATH) which ruby or use command -v in place of which, as recommended in Why not use ...
You generally don't want to use the which command. In Bash you should be using the type or command commands. See this Q&A for reasons why, titled: Why not use “which”? What to use then?. Examples $ type -a ls ls is aliased to `ls --color=auto' ls is /bin/ls or this: $ type -a vim vim is /usr/bin/vim or this: $ command -v ls alias ls='ls ...
Explicitly setting the value of $PATH in the sub-shell resolves the problem: env -i sh -c "PATH=\$PATH which ruby" Note that the $ in $PATH is escaped, which means that $PATH in the sub-shell command isn't substituted with the parent shell's value of $PATH before the command is executed (this could also be achieved using single quotes). I'd be really ...
Speecify the PATH setting of simply "/usr/bin" (or set PATH to suit) as a parameter to env. env -i ignores the environment it inherits, the following PATH setting will enable which to find /usr/bin/ruby. env -i PATH="/usr/bin" sh -c "which ruby"
Top 50 recent answers are included