I assume that your question is how bash can know to change the directory so that the working directory is
foo (rather than
While these two paths will be are represented by the same inode (unless there are symlinks present in the path, as shown at the end of this answer), the shell does need to take special measures to show the current directory name as
foo, rather than
.. in the path, it internally just strips the parent directory away, meaning that
.. can never be the directory name.
This is documented in
.. is processed by removing the immediately previous pathname component back to a slash or the beginning of DIR.
This special casing results in the following interesting behaviour (note that
foo/qux/.. still resolved to
foo, even when the real path was
| `-- baz
3 directories, 0 files
$ ln -s "$(readlink -f bar/baz)" foo/qux
| `-- baz
`-- qux -> bar/baz
4 directories, 0 files
$ cd foo/qux/..
$ basename "$(pwd)"