The issue is more for sudo cd
to fail on your OS than sudo echo
to succeed.
sudo cd /directory
is quite a legitimate method to check if a given user, likely root
here, is allowed to cd
to some directory. That is the reason why all Posix compliant OSes do provide an executable version of cd
.
So the answer to you question is sudo echo yo
works by design because echo
is provided by both a shell alias and an executable command but sudo cd /directory
does not because your OS, likely Gnu/Linux based, is breaking the Posix standard in this specific case.
A simple workaround for your system would be to run sudo sh -c "cd /directory"
sudo cd /directory
works fine here. Check thatwhich cd
is in your root user's$PATH
. – ceejayoz Oct 16 '14 at 15:01