Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: ksh compatibility: initial value of $_



Sorry, maybe I completely misunderstood the ksh behavior.

    _    Initially,  the value of _ is an absolute pathname of the
         shell or script being executed as passed in the environment.

So zsh can just do the same thing?
With the following patch, zsh behaves similarly with ksh?


diff --git a/Src/init.c b/Src/init.c
index 68621a0ad..fcfa7c3c9 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -1084,9 +1084,18 @@ setupvals(char *cmd, char *runscript, char *zsh_name)
 	ztrdup(DEFAULT_IFS_SH) : ztrdup(DEFAULT_IFS);
     wordchars   = ztrdup(DEFAULT_WORDCHARS);
     postedit    = ztrdup("");
-    zunderscore  = (char *) zalloc(underscorelen = 32);
-    underscoreused = 1;
-    *zunderscore = '\0';
+    zunderscore = getenv("_");
+    if (zunderscore) {
+	zunderscore = metafy(ztrdup(zunderscore), -1, META_REALLOC);
+	underscoreused = strlen(zunderscore) + 1;
+	underscorelen = (underscoreused + 31) & ~31;
+	zunderscore = (char *)zrealloc(zunderscore, underscorelen);
+    }
+    else {
+	zunderscore  = (char *)zalloc(underscorelen = 32);
+	underscoreused = 1;
+	*zunderscore = '\0';
+    }
 
     zoptarg = ztrdup("");
     zoptind = 1;





Messages sorted by: Reverse Date, Date, Thread, Author