On a target machine (OS X El Capitan) I have brew in /usr/local/bin. When I try to get brew's path I get no result:
# ssh [email protected] -p 2222 which brew
#
Troubleshooting:
brewis in/usr/local/bin/and executes properly viassh:# ssh [email protected] -p 2222 ls -l /usr/local/bin/brew -rwxr-xr-x 1 vagrant admin 656 Mar 20 10:05 /usr/local/bin/brew # ssh [email protected] -p 2222 /usr/local/bin/brew --version Homebrew 0.9.5 (git revision 3a41; last commit 2016-03-20)There is
/usr/local/binin path:# ssh [email protected] -p 2222 echo $PATH /usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/opt/local/bin:/opt/local/sbinwhichitself does not seem to have a problem:# ssh [email protected] -p 2222 which bash /bin/bashAlso when logged interactively to the machine I get the intended result:
# ssh [email protected] -p 2222 Last login: Sun Mar 20 12:02:55 2016 from 10.0.2.2 osx-pf:~ vagrant$ which brew /usr/local/bin/brewFinally
which brewworks when in command substitution expression:# ssh [email protected] -p 2222 echo $(which brew) /usr/local/bin/brewCalling
echobeforewhich brewcauses it to give the correct result:# ssh [email protected] -p 2222 echo test ; which brew test /usr/local/bin/brewCalling shell explicitly to run
which brewdoes not change the situation:# ssh [email protected] -p 2222 /bin/sh -c "which\ brew" # ssh [email protected] -p 2222 /bin/sh -c "which\ which" /usr/bin/whichHowever with explicit call to
/bin/shthe "trick" from (6) no longer works:# ssh [email protected] -p 2222 /bin/sh -c "echo\ test\ \;\ which\ brew" test #
Why running which brew directly as an ssh command argument fails?
Why echo which external command in /bin/echo sees proper PATH while which does not? And why running two commands in sequence causes the second one to use environment of the first?
Is it possible to assure the environment would be loaded without referring to undocumented (I presume) workarounds like in (6)?