Brad Lanam <
brad....@gmail.com> wrote:
> On Tuesday, December 5, 2017 at 8:22:43 AM UTC-8,
tcl...@gmail.com wrote:
>> I have something strange happening with a script that goes through a directory structure.
>> To test it I created a directory call "Test" and put there several empty directories "A", "B", "C", "CA", "CB" and "CC".
>> I open tclsh8.6 in the test directory and run the following script:
>> [root@Backup Test]# tclsh8.6
>> % foreach dir [glob */] { puts "$dir" ; cd "$dir"; puts [pwd] ; cd ..}
> Also, after the bug occurs, one of the cd/pwd command stops working properly
> either cd doesn't work or pwd does not report properly.
After the bug occurs, pwd reports some super-super-super-directory,
and glob * shows the contents of that s.-s.-s.-dir.
But then, [exec pwd] still reports the original directory where I started from
and [exec ls] shows the mentioned test-subdirs "A", "B", "C", "CA", "CB" and "CC".
At this point, even "cd [exec pwd]" does nothing (and in particular
not repair the internal state), while cd'ing to a super-dir of the
original dir does repair the internal mess.
fwiw & thanks to OP for reporting it!
I'm glad that OP tried that way and thus found this bug, but in general,
I'd recommend saving the [pwd] and always cd to the saved dir, rather than
relying on ".." - there are traps that may catch you, like symlinks, or
directories being moved while you're inside them...