This question is different from In Bash, how can I detect if I'm in a subshell? because it's not shell specific.
Let's say I open a terminal, which is zsh
. I can go deep into that like this,
$ echo $$
359648
$ zsh
$ echo $$
359706
$ zsh
$ echo $$
359746
$ exit
$ echo $$
359706
$ exit
$ echo $$
359648
I want the first invocation of zsh
to realize that we're already in zsh
and to refuse the the creation of a subshell. Realizing that a shell is just a regular program and the notion of a "subshell" is just a basic abstraction when you so happen to spawn the same shell in a parent shell, is this even possible?
- Is it possible to detect when this condition would be reached?
- Is it possible to detect when this condition has already occured.
This question is not specific to zsh
zsh() { echo sorry; }
– ilkkachu Mar 05 '23 at 20:34