about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2024-07-28 20:33:07 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2024-07-28 20:33:07 +0100
commit0bb140f9911851e9712dba311925f9c9ab521fd2 (patch)
treeaccadafa16f09e9aff93f3ba4a3d3a46fb9ca0d5 /Src
parent09c5b10dc2affbe4e46f69e64d573b197c14b988 (diff)
downloadzsh-0bb140f9911851e9712dba311925f9c9ab521fd2.tar.gz
zsh-0bb140f9911851e9712dba311925f9c9ab521fd2.tar.xz
zsh-0bb140f9911851e9712dba311925f9c9ab521fd2.zip
52999: import OLDPWD from environment if set
Diffstat (limited to 'Src')
-rw-r--r--Src/init.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/Src/init.c b/Src/init.c
index ec21521b1..0aecb5db9 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -1245,7 +1245,11 @@ 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' */
+    else
+	oldpwd = ztrdup(oldpwd);
 
     inittyptab();     /* initialize the ztypes table */
     initlextabs();    /* initialize lexing tables    */