From: Franklin Yu <FranklinYu@hotmail.com>
To: "Lawrence Velázquez" <larryv@zsh.org>
Cc: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: inherit OLDPWD from environment variable
Date: Sat, 20 Jul 2024 07:56:01 +0000 [thread overview]
Message-ID: <BL1PR14MB5121EE3B1A11C38ECEF29F01D8AE2@BL1PR14MB5121.namprd14.prod.outlook.com> (raw)
In-Reply-To: <910a3a7e-ea58-4f2f-b26e-a2fff7d5c0c3@app.fastmail.com>
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@zsh.org>
Sent: 19 July 2024 19:46
To: Franklin Yu <franklinyu@hotmail.com>
Cc: zsh-workers@zsh.org <zsh-workers@zsh.org>
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
next prev parent reply other threads:[~2024-07-20 7:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-20 1:55 Franklin Yu
2024-07-20 2:46 ` Lawrence Velázquez
2024-07-20 7:56 ` Franklin Yu [this message]
2024-07-21 19:30 ` Peter Stephenson
2024-07-21 20:48 ` Peter Stephenson
-- strict thread matches above, loose matches on Subject: below --
2024-07-17 7:59 Franklin Yu
2024-07-17 9:02 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BL1PR14MB5121EE3B1A11C38ECEF29F01D8AE2@BL1PR14MB5121.namprd14.prod.outlook.com \
--to=franklinyu@hotmail.com \
--cc=larryv@zsh.org \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).