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

Re: inherit OLDPWD from environment variable



Good catch. Indeed Bash accepts empty value. Then it becomes

diff --git a/Src/init.c b/Src/init.c
index ec21521b1..092273228 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -1245,7 +1245,9 @@ setupvals(char *cmd, char *runscript, char *zsh_name)
        pwd = metafy(zgetcwd(), -1, META_DUP);
     }

-    oldpwd = ztrdup(pwd);  /* initialize `OLDPWD' = `PWD' */
+    oldpwd = zgetenv("OLDPWD");
+    if (oldpwd == NULL)
+        oldpwd = ztrdup(pwd);  /* initialize `OLDPWD' = `PWD' */

     inittyptab();     /* initialize the ztypes table */
     initlextabs();    /* initialize lexing tables    */

________________________________________
From: Lawrence Velázquez <larryv@xxxxxxx>
Sent: 19 July 2024 19:46
To: Franklin Yu <franklinyu@xxxxxxxxxxx>
Cc: zsh-workers@xxxxxxx <zsh-workers@xxxxxxx>
Subject: Re: inherit OLDPWD from environment variable
 
On Fri, Jul 19, 2024, at 9:55 PM, Franklin Yu wrote:
> -    oldpwd = ztrdup(pwd);  /* initialize `OLDPWD' = `PWD' */
> +    oldpwd = zgetenv("OLDPWD");
> +    if (oldpwd == NULL || oldpwd[0] == '\0')
> +        oldpwd = ztrdup(pwd);  /* initialize `OLDPWD' = `PWD' */

If we're going to begin importing OLDPWD from the environment, we
might as well align with other shells for consistency, which means
accepting a zero-length value as is.  This is how bash 5.2.26, dash
0.5.12, ksh93u+ 2012-08-01, mksh R59, and yash 2.56.1 all behave.

--
vq



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