1
I was checking the path of cd
command in macOS terminal using which cd
, I got /usr/bin/cd
, so whenever I use this full path to execute cd
it doesn't work as expected.
So here are some examples.
Any valid path here root(
/
) as arg./usr/bin/cd /
-> doesn't change dir as specifiedAny invalid path here (kjfd) as arg.
/usr/bin/cd kjfd
->/usr/bin/cd: line 4: cd: kjfd: No such file or directory
So, I really don't understand why cd
with complete path address(/usr/bin/cd /
) is not working while other commands like bin/echo
do work.
The point is any executable changes its own working directory (if ever)
, I really didn't get you here, could you help, please? – codeitram – 2019-07-13T17:39:28.2472@codeitram Each process has its own working directory; if
cd
runs in as a separate process from the shell (which /usr/bin/cd does), when it changes directory it's changing the directory of thecd
process, not that of the shell process. You wanted the shell process's directory to change. In order to change the shell process's directory, the change must be done in that process (i.e. in the shell itself), not in another process. – Gordon Davisson – 2019-07-13T20:15:38.380