zsh-workers
 help / color / mirror / code / Atom feed
From: Jun T <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: ksh compatibility: initial value of $_
Date: Fri, 31 Mar 2023 17:18:52 +0900	[thread overview]
Message-ID: <E425509B-3108-4E1F-B141-F3AD767A87D4@kba.biglobe.ne.jp> (raw)
In-Reply-To: <F3EB0C55-C453-4C49-BA7A-7ED3826E43A0@kba.biglobe.ne.jp>


> 2023/03/23 19:40, I wrote:
> 
>> 2023/01/28 10:52, Bart Schaefer <schaefer@brasslantern.com> wrote:
>> 
>> 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.

$_ need to be initialized to the full pathname of either
current zsh executable, or the script file.
I have some difficulty with both.

[1] full pathname of the zsh executable:

On Linux we can use /proc/self/exe.

By some Googling I've found that Solaris, NetBSD, and DragonFly have
similar symlinks in /proc. On macOS we can use _NSGetExecutablePath().

On FreeBSD, it seems porcfs is obsolete.
On OpenBSD there seems to be no reliable way?

But, for {Free,Open}BSD just guessing from argv[0] and $PATH or $PWD
would be enough, although argv[0] can be set to arbitray value in
execve(2).


[2] full pathname of the script file

We can guess it from argv[1] (after removing options) and $PWD, and the
variable 'runscript' is set to argv[1] at line 290 in init.c.

But, suppose we have a ksh script 'foo' in the current directory:

% cat foo
#!/usr/bin/ksh
echo $_
% ./foo
/home/takimoto/tmp/./foo
% ksh ./foo
/usr/bin/ksh

How can we distinguish these two cases? In both cases runscript is
'./foo', I think. Probably there is a simple way that I just don't know.


  reply	other threads:[~2023-03-31  8:19 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-28  1:52 Bart Schaefer
2023-03-23 10:40 ` Jun T
2023-03-31  8:18   ` Jun T [this message]
2023-03-31 14:31     ` Jun. T
2023-03-31 17:45       ` Bart Schaefer
2023-04-03 11:16         ` Jun. T
2023-04-03 16:48           ` Bart Schaefer
2023-03-31 19:02       ` Bart Schaefer
2023-03-31 19:03         ` Bart Schaefer
2023-04-03 12:13     ` Jun. T
2023-04-03 16:50       ` Bart Schaefer
2023-04-04 16:24         ` Jun. T
2023-04-05  1:03           ` Oliver Kiddle
2023-04-05  8:15             ` zeurkous
2023-04-05  9:00               ` Oliver Kiddle
2023-04-05 16:24             ` Jun. T
2023-04-05  8:14           ` dana
2023-04-05 18:16             ` Jun. T
2023-04-08  4:03               ` dana
2023-04-08 16:22                 ` Oliver Kiddle
2023-04-09 13:30                   ` Jun. T
2023-04-10  0:51                     ` Jun T
2023-04-15  5:02                   ` Felipe Contreras
2023-04-15 22:24               ` Bart Schaefer

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=E425509B-3108-4E1F-B141-F3AD767A87D4@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --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).