Index: /trunk/src/kash/eval.c
===================================================================
--- /trunk/src/kash/eval.c	(revision 2652)
+++ /trunk/src/kash/eval.c	(revision 2653)
@@ -706,4 +706,7 @@
 	psh->back_exitstatus = 0;
 
+	/** @todo r=bird: Why is arguments and envvars expanded in this
+	 * particular order?  It would be both faster and simpler to do the
+	 * envvars first and then continue with the arguments... */
 	arglist.lastp = &arglist.list;
 	varflag = 1;
Index: /trunk/src/kash/expand.c
===================================================================
--- /trunk/src/kash/expand.c	(revision 2652)
+++ /trunk/src/kash/expand.c	(revision 2653)
@@ -143,4 +143,5 @@
 	STPUTC(psh, '\0', psh->expdest);
 	p = grabstackstr(psh, psh->expdest);
+	TRACE2((psh, "expandarg: p='%s'\n", p));
 	psh->exparg.lastp = &psh->exparg.list;
 	/*
@@ -1204,4 +1205,5 @@
 		if (metaflag == 0 || shfile_lstat(&psh->fdtab, psh->expdir, &statb) >= 0)
 			addfname(psh, psh->expdir);
+		TRACE2((psh, "expandarg: return #1 (metaflag=%d)\n", metaflag));
 		return;
 	}
@@ -1225,6 +1227,8 @@
 		enddir[-1] = '\0';
 	}
-	if ((dirp = shfile_opendir(&psh->fdtab, cp)) == NULL)
+	if ((dirp = shfile_opendir(&psh->fdtab, cp)) == NULL) {
+		TRACE2((psh, "expandarg: return #2 (shfile_opendir(,%s) failed)\n", cp));
 		return;
+	}
 	if (enddir != psh->expdir)
 		enddir[-1] = '/';
Index: /trunk/src/kash/shfile.c
===================================================================
--- /trunk/src/kash/shfile.c	(revision 2652)
+++ /trunk/src/kash/shfile.c	(revision 2653)
@@ -1808,4 +1808,6 @@
     shdir  *pdir = NULL;
 
+    TRACE2((NULL, "shfile_opendir: dir='%s'\n", dir));
+    shfile_init_globals();
     if (g_pfnNtQueryDirectoryFile)
     {
@@ -1840,5 +1842,8 @@
             }
             else
-                shfile_dos2errno(GetLastError());
+            {
+                errno = shfile_dos2errno(GetLastError());
+                TRACE2((NULL, "shfile_opendir: CreateFileA(%s) -> %d/%d\n", abspath, GetLastError(), errno));
+            }
         }
     }
@@ -1847,4 +1852,5 @@
     return pdir;
 #else
+    TRACE2((NULL, "shfile_opendir: dir='%s'\n", dir));
     return (shdir *)opendir(dir);
 #endif
