Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: ksh compatibility: initial value of $_
- X-seq: zsh-workers 51598
- From: Jun T <takimoto-j@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: ksh compatibility: initial value of $_
- Date: Thu, 23 Mar 2023 19:40:57 +0900
- Archived-at: <https://zsh.org/workers/51598>
- In-reply-to: <CAH+w=7a5Pk5nk4+k_d7TCcBjE04TwXJTm7Xrre9SYdK_U-hLmQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAH+w=7a5Pk5nk4+k_d7TCcBjE04TwXJTm7Xrre9SYdK_U-hLmQ@mail.gmail.com>
> 2023/01/28 10:52, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> Docs for ksh93 say that $_ should be initialized to the absolute path
> of what we put in $ZSH_ARGZERO.
>
> Src/init.c explicitly initializes $_ to the empty string.
>
> Any reason not to change this?
No reason, I think, but I don't know any portable way to obtain
the full path name of the current zsh executable.
> If so, where's the right place to do
> it? I tried doing it in createparamtab() but that led to memory
> errors.
Once the full path name is obtained, then I guess we can initialize
$_ in setupvals() as in the following pseudo-patch:
diff --git a/Src/init.c b/Src/init.c
index 68621a0ad..03cbe4d0e 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -1084,9 +1084,12 @@ 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';
+ /* assume full path name of this zsh is in 'mypath' */
+ underscoreused = strlen(mypath) + 1;
+ underscorelen = (underscoreused + 31) & ~31;
+ zunderscore = (char *) zalloc(underscorelen);
+ strcpy(zunderscore, mypath);
+ /* free 'mypath' if necessary */
zoptarg = ztrdup("");
zoptind = 1;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author