I am executing following command.
cd dirname; echo $?
This always return 0 whether of not cd is successful. This is giving me incredible headache.
How to check if cd was successful without reading its error message.
I am executing following command.
cd dirname; echo $?
This always return 0 whether of not cd is successful. This is giving me incredible headache.
How to check if cd was successful without reading its error message.
The reason may be that cd is not a shell builtin as usual but
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.
The same thing happened to me. As all others mentioning, it was because my "cd" was wrapped by a function.
Anyway, this should be worked.
command cd /mnt/c/nowhere && echo y # does not console "y"
One solution is to prefix the call w/ the bash builtin 'command'. This will force the use of the actual binary file 'cd'
root@ds002:~# command cd /foo
-bash: cd: /foo: No such file or directory
root@ds002:~# echo $?
1