* how to get the absolute pathname of the current shell?
@ 2013-12-06 13:27 Vincent Lefevre
2013-12-06 16:30 ` Bart Schaefer
0 siblings, 1 reply; 5+ messages in thread
From: Vincent Lefevre @ 2013-12-06 13:27 UTC (permalink / raw)
To: zsh-users
I'd like to get an absolute pathname of the current shell, for
interactive shells (i.e. scripts are not concerned), in a startup
file (so that the current working directory has not changed).
The goal is to set $SHELL to the current shell.
Currently I'm doing: ${$(whence -p ${0#-}):a}
But this doesn't work when there are symbolic links, for instance,
when one has:
foo -> bar/subdir
my_shell -> /bin/zsh
foo/../../my_shell executes my_shell as expected, but the ":a"
gives: /home/my_shell
Note that I have the CHASE_LINKS option set, but the solution
shouldn't depend on this setting.
I want something portable, thus I don't want to rely on a realpath
command or /proc.
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: how to get the absolute pathname of the current shell?
2013-12-06 13:27 how to get the absolute pathname of the current shell? Vincent Lefevre
@ 2013-12-06 16:30 ` Bart Schaefer
2013-12-09 8:53 ` Vincent Lefevre
0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2013-12-06 16:30 UTC (permalink / raw)
To: zsh-users
On Dec 6, 2:27pm, Vincent Lefevre wrote:
}
} I'd like to get an absolute pathname of the current shell, for
} interactive shells (i.e. scripts are not concerned), in a startup
} file (so that the current working directory has not changed).
As far as I can tell there is no portable way to do this. Even C
programs have to use different code depending on the OS.
} Currently I'm doing: ${$(whence -p ${0#-}):a}
}
} But this doesn't work when there are symbolic links
If the above is otherwise good enough, why not ${$(whence -p ${0#-}):A}
which uses realpath() when it is available? [See above about different
code depending on OS ...]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: how to get the absolute pathname of the current shell?
2013-12-06 16:30 ` Bart Schaefer
@ 2013-12-09 8:53 ` Vincent Lefevre
2013-12-09 9:31 ` Vincent Lefevre
2013-12-09 9:45 ` Vincent Lefevre
0 siblings, 2 replies; 5+ messages in thread
From: Vincent Lefevre @ 2013-12-09 8:53 UTC (permalink / raw)
To: zsh-users
On 2013-12-06 08:30:20 -0800, Bart Schaefer wrote:
> On Dec 6, 2:27pm, Vincent Lefevre wrote:
> } Currently I'm doing: ${$(whence -p ${0#-}):a}
> }
> } But this doesn't work when there are symbolic links
>
> If the above is otherwise good enough, why not ${$(whence -p ${0#-}):A}
> which uses realpath() when it is available? [See above about different
> code depending on OS ...]
Using :A instead of :a doesn't solve the problem.
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: how to get the absolute pathname of the current shell?
2013-12-09 8:53 ` Vincent Lefevre
@ 2013-12-09 9:31 ` Vincent Lefevre
2013-12-09 9:45 ` Vincent Lefevre
1 sibling, 0 replies; 5+ messages in thread
From: Vincent Lefevre @ 2013-12-09 9:31 UTC (permalink / raw)
To: zsh-users
On 2013-12-09 09:53:30 +0100, Vincent Lefevre wrote:
> On 2013-12-06 08:30:20 -0800, Bart Schaefer wrote:
> > On Dec 6, 2:27pm, Vincent Lefevre wrote:
> > } Currently I'm doing: ${$(whence -p ${0#-}):a}
> > }
> > } But this doesn't work when there are symbolic links
> >
> > If the above is otherwise good enough, why not ${$(whence -p ${0#-}):A}
> > which uses realpath() when it is available? [See above about different
> > code depending on OS ...]
>
> Using :A instead of :a doesn't solve the problem.
The following code seems to work:
tmp=$(whence -p ${0#-})
SHELL=${${tmp##/*}:+$PWD/}$tmp
It avoids buggy symbolic link resolution.
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: how to get the absolute pathname of the current shell?
2013-12-09 8:53 ` Vincent Lefevre
2013-12-09 9:31 ` Vincent Lefevre
@ 2013-12-09 9:45 ` Vincent Lefevre
1 sibling, 0 replies; 5+ messages in thread
From: Vincent Lefevre @ 2013-12-09 9:45 UTC (permalink / raw)
To: zsh-users
On 2013-12-09 09:53:30 +0100, Vincent Lefevre wrote:
> On 2013-12-06 08:30:20 -0800, Bart Schaefer wrote:
> > On Dec 6, 2:27pm, Vincent Lefevre wrote:
> > } Currently I'm doing: ${$(whence -p ${0#-}):a}
> > }
> > } But this doesn't work when there are symbolic links
> >
> > If the above is otherwise good enough, why not ${$(whence -p ${0#-}):A}
> > which uses realpath() when it is available? [See above about different
> > code depending on OS ...]
>
> Using :A instead of :a doesn't solve the problem.
After looking more closely, this is because "resolution of `..' occurs
before resolution of symbolic links" (see zshexpn(1) man page). Since
zsh's resolution of `..' is broken by design, i.e. incompatible with
real resolution, as done by realpath (and the Linux kernel), :A and :a
mustn't be used here.
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-12-09 9:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-06 13:27 how to get the absolute pathname of the current shell? Vincent Lefevre
2013-12-06 16:30 ` Bart Schaefer
2013-12-09 8:53 ` Vincent Lefevre
2013-12-09 9:31 ` Vincent Lefevre
2013-12-09 9:45 ` Vincent Lefevre
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).