glob -dir $dir -tail returns name with leading / if $dir ends in a /
Closed / Fixede860418c2d20c7bf93f751b9d56dd2644440a45aCreated 196 days agoUpdated 192 days ago
Descriptionmarkdown2026-05-21 06:58:31
Originally reported by @JulianNoble in the discussion in unrelated issue 596936dd2d
When you do a glob -dir $dir -tail on a dir ending in a slash - it can return /name instead of just name
Then the file join fails to work as it takes the name as an absolute path and doesn't add the dir.
#with trailing slash in path
% set path {C:\Program Files\PowerShell\7}
C:\Program Files\PowerShell\7
% tcl::unsupported::representation $path
value is a pure string with a refcount of 4, object pointer at 0x1ea036f3270, string representation "C:\Program Fi..."
% append path \\
C:\Program Files\PowerShell\7\
% tcl::unsupported::representation $path
value is a utf32string with a refcount of 2, object pointer at 0x1ea036ef2e0, internal representation 0x1ea038c70b0:0x0, string representation "C:\Program Fi..."
% glob -dir $path -tail pwsh.exe
/pwsh.exe
#without trailing slash
% set path {C:\Program Files\PowerShell\7}
C:\Program Files\PowerShell\7
% tcl::unsupported::representation $path
value is a pure string with a refcount of 5, object pointer at 0x1ea036f3270, string representation "C:\Program Fi..."
% glob -dir $path -tail pwsh.exe
pwsh.exe
Whether or not a trailing slash should strictly exist at the end of a path - I believe it to be fairly common on windows (some installers do it) and it should work.
Tcl8.5 on the other hand does it correctly:
% glob -dir "c:\\" -tail windows-version.txt
windows-version.txt
versus testing in 8.6, 8.7, 9.0
% glob -dir "c:\\" -tail windows-version.txt
/windows-version.txt
apnadkarnimarkdown2026-05-24 09:13:24
Forward slashes seem to work fine.
% glob -dir c:/ -tail windows
windows
And without -tail output seem ok but weird, unnecessary escaping.
% glob -dir c:\\ windows
{c:\/windows}
apnadkarnimarkdown2026-05-24 11:19:56
And my second example, which I thought was cosmetic, is also a bug (double escapes).
Proposed fix for both in bug-e860418c branch.
apnadkarniplain2026-05-25 11:01:34
Fixed in [9f84d3ca4d] for 9.0.4 onward.
Log in (anonymous is fine) to add a comment.