The other day I was setting up my shell environment on a different 
system, starting with copying over my .profile and .kshrc, along with
a few other scripts.

Later I tried to run one of my scripts in a different window, but that 
window's ksh93 couldn't find it, while other shells in my other windows
could.  After digging a big, I realized that the one shell was started
during the window of time where my .kshrc ( with my scripts directory 
added to $PATH ) had been copied to the new system, but before the 
scripts directory had been created.  Since the directory did not exist 
at the time $PATH was set, ksh93 was not attempting to access it again.

Here's a transcript of me reproducing the same conditions:

     ivan at excalibur:~$ echo $PATH
     /usr/bin:/usr/sfw/bin:/usr/ccs/bin:/usr/X11/bin
     ivan at excalibur:~$ PATH=$PATH:~/bin
     ivan at excalibur:~$ mkdir bin
     ivan at excalibur:~$ cp /usr/bin/hostname bin/foo
     ivan at excalibur:~$ foo
     ksh93: foo: not found [No such file or directory]
     ivan at excalibur:~$ ~/bin/foo
     excalibur
     ivan at excalibur:~$ PATH=$PATH
     ivan at excalibur:~$ foo
     ksh93: foo: not found [No such file or directory]
     ivan at excalibur:~$ A=$PATH
     ivan at excalibur:~$ PATH=.
     ivan at excalibur:~$ PATH=$A
     ivan at excalibur:~$ foo
     excalibur
     ivan at excalibur:~$

Watching the process with truss, I can see it walk down the directories 
in $PATH, except the the directory that previously didn't exist:

     write(4, " f o o\n\0\0", 6)                        = 6
     lseek(4, 0, SEEK_CUR)                              = 17082
     stat("/usr/bin/foo", 0xFFFFFD7FFFDFE1F0)   Err#2 ENOENT
     stat("/usr/sfw/bin/foo", 0xFFFFFD7FFFDFE1F0)       Err#2 ENOENT
     stat("/usr/ccs/bin/foo", 0xFFFFFD7FFFDFE1F0)       Err#2 ENOENT
     stat("/usr/X11/bin/foo", 0xFFFFFD7FFFDFE1F0)       Err#2 ENOENT
     stat("/usr/bin/foo", 0xFFFFFD7FFFDFE070)   Err#2 ENOENT
     stat("/usr/sfw/bin/foo", 0xFFFFFD7FFFDFE070)       Err#2 ENOENT
     stat("/usr/ccs/bin/foo", 0xFFFFFD7FFFDFE070)       Err#2 ENOENT
     stat("/usr/X11/bin/foo", 0xFFFFFD7FFFDFE070)       Err#2 ENOENT
     write(2, 0x004175B0, 50)                   = 50
        k s h 9 3 :   f o o :   n o t   f o u n d   [ N o   s u c h   f
        i l e   o r   d i r e c t o r y ]\n
     time()                                             = 1234473863

This happens in ksh93 in OpenSolaris/Solaris Express, but not with the 
older version of dtksh that's included with Solaris Express.

     ivan at excalibur:~$ uname -a 

     SunOS excalibur 5.11 snv_89 i86pc i386 i86pc 

     ivan at excalibur:~$ echo ${.sh.version} 

     Version M 1993-12-28 s+

     ivan at ciara:~$ uname -a 

     SunOS ciara 5.11 snv_106 i86pc i386 i86pc
     ivan at ciara:~$ echo ${.sh.version} 

     Version M 93t 2008-11-04
     ivan at ciara:~$ /usr/dt/bin/dtksh
     $ echo ${.sh.version}
     Version M-12/28/93d


Working around it is simple, just change $PATH again.  But it had me 
puzzled the other day when I ran into it.  Is this is the way it's 
supposed to behave, or is it a bug?

Ivan.


Reply via email to