Fix shell `cd` error when working dir has been deleted (#41244)
root cause:
if current dir has been deleted, then pwd() will throw an IOError:
pwd(): no such file or directory (ENOENT)
---------
Co-authored-by: Ian Butterworth <i.r.butterworth@gmail.com>