Return status of `cd` is always 0

The reason may be that cd is not a shell builtin as usual but

  1. a shell function
  2. or an alias

This can be checked with type cd.

(I make the comment an answer so that the question can be "closed".)


My stupidity!

As suggested by HaukeLaging, I did type cd. It turned out the cd was aliased to some bash function which was logging the user cd activity on the server.

I aliased cd back to cd and the script started working fine. I had the fleeting temptation to delete the question altogether first the I thought I should answer it here. I might be useful for someone else.

Tags:

Bash