Cd not working when redirecting output?

Here is the puzzle: can someone explain why it cdfails when the output is redirected to the channel?

eg:.

james@machine:~$ cd /tmp                          # fine, no problem
james@machine:~$ cd /tmp | grep 'foo'             # doesn't work
james@machine:~$ cd /tmp | tee -a output.log      # doesn't work
james@machine:~$ cd /tmp >out.log                 # does work

Tested on OSX, Ubuntu and RHEL.

Any ideas?

EDIT : It seems strange that I am collecting a conclusion cd? The reason is because it is from a function that wraps arbitrary shell commands with log entries and output processing.

+3
source share
1 answer

, . , , .

+13

All Articles