| Ticket UUID: | 3570244 | ||
| Title: | "cd .." behaves wrong if last element in pwd is a symlink | ||
| Type: | Bug | Created on: | 2012-09-20 21:26:59 |
| Submitter: | wastl-nagel | Assigned to: | dgp |
| Subsystem: | 37. File System | Severity: | |
| Priority: | 5 Medium | Last modified: | 2026-10-19 18:44:30 |
| Status: | Open | Closed by: | |
| Resolution: | None | Closed on: | |
| Version: | 8.6.18, 9.0.5, 9.1.0 | ||
| Description: | ||||
If the last element of a the current path (pwd) is a symbolic link with a trailing slash the command cd .. does not change into the parent directory but stays in the current directory. In addition, when the link target is a relative path containing ".." or "." the pwd after "cd .." may require normalization. Related / possible duplicate of "cd .. from link in Windows confuses Tcl - ID: 3183016" bash> pwd /tmp/test bash> mkdir /tmp/dir bash> ln -sf /tmp/dir link_abs bash> tclsh % cd link_abs % pwd /tmp/test/link_abs % cd .. % pwd ;# ok we are in /tmp (/tmp/test would be also plausible) /tmp % exit bash> ln -sf /tmp/dir/ link_abs_trailing_slash bash> tclsh % cd link_abs_trailing_slash % pwd /tmp/test/link_abs_trailing_slash % cd .. ;# should cd to /tmp (or /tmp/test) % pwd ;# surprise: we stay in same effective directory /tmp/dir % exit bash> ln -sf /tmp/dir link_rel bash> tclsh % cd link_rel % pwd /tmp/test/link_rel % cd .. % pwd ;# ok, but should be normalized /tmp/test/.. % file normalize [pwd] /tmp % exit bash> ln -sf ../dir/ link_rel_trailing_slash bash> tclsh % cd link_rel_trailing_slash % pwd /tmp/test/link_rel_trailing_slash % cd .. % pwd ;# surprise /tmp/dir % exit bash> ln -sf ./link_abs link2link bash> tclsh % cd link2link % pwd /tmp/test/link2link % cd .. ;# now we are in /tmp/test (also ok) % pwd ;# but should be normalized /tmp/test/. % file normalize [pwd] /tmp % puts "$::tcl_patchLevel, $::tcl_platform(os) $::tcl_platform(osVersion)" 8.5.11, Linux 3.2.0-30-generic % exit | ||||
| User Comments: | ||||
dkf added on 2012-09-21 14:50:50:
Whatever is going on, it's a feature of the file system engine and not the [cd] command itself. I suspect that it depends on what normalization does, and I know that Don Porter has been doing work in that area relatively recently. Is it possible to retest with 8.5.12 or 8.6b3? wastl-nagel added on 2012-09-21 18:56:51:
Both 8.5.12 and 8.6b3 are affected as well serhiy.storchaka added on 2026-10-19 18:44:30:
Still present in 8.6, 9.0 and 9.1. As dkf suspected, the cause is in normalization: when ".." follows a link, the link target is used literally ([3577801fff]). Proposed fix in branch normalize-dotdot-after-link: on Unix [cd ..] now goes to the parent of the link target in all five cases of the report, as cd -P .. does. Test filesystem-1.56. | ||||
