Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How to detect that Zsh startup is result of exec zsh?



> On Sep 15, 2016, at 2:31 AM, Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
> 
> On 13 September 2016 at 15:30, Peter Stephenson
> <p.stephenson@xxxxxxxxxxx> wrote:
>> BTW, telling you're in a subshell when you're still in the parent shell
>> is actually easy:
>> 
>> zmodload zsh/system
>> if (( $$ ==  $sysparams[pid] )); then
>>  print "I'm in the parent shell"
>> else
>>  print "I'm in a subshell"
>> fi
>> 
>> However, that's too early for you --- you need to know at the start of
>> the new zsh.  I think some external mapping to PIDs is the only reliable
>> way.
>> 
>> pws
> 
> For me the two values are always the same:
> https://asciinema.org/a/1tpk0k6jii36iwrzawlr2ador
> 
> This reminds me $ZSH_SUBSHELL that Mikael proposed, which is always 0 for me:
> https://asciinema.org/a/1jtfup4jrl14w7bps84wupqai
> 
> Testing this on IRC bot gave correct result, i.e. "1" was assigned
> after running zsh IIRC. So maybe this is OS X issue, maybe even the
> same in both cases?

You're not actually using any subshells.

% zsh --version
zsh 5.2 (x86_64-apple-darwin15.6.0)
% typeset ZSH_SUBSHELL
ZSH_SUBSHELL=0
% (typeset ZSH_SUBSHELL)
ZSH_SUBSHELL=1
% ( (typeset ZSH_SUBSHELL) )
ZSH_SUBSHELL=2
% zmodload zsh/system
% (( $$ == $sysparams[pid] )); echo $?
0
% ( (( $$ == $sysparams[pid] )); echo $?)
1


vq


Messages sorted by: Reverse Date, Date, Thread, Author