LeaYeh/minishell

[OPTIONAL] Add `SHLVL` to environment and default environment

itislu opened this issue · 4 comments

It's quite simple.
If SHLVL variable exists in environment, +1 it when initing the shell.
If SHLVL variable does not exist, create it in the default environment with value 1.

The maximum SHLVL is 999.
If SHLVL is set to 999 and another shell is called, the following error occurs in the new shell:
bash: warning: shell level (1000) too high, resetting to 1.
If SHLVL was manually set to a value higher than 999, 1000 is replaced with whatever value it would now be after +1 the previous value.

I know it but I dont see any different between store in shell structure or env, I will keep in mind when one day I decide to do 42sh

There is a difference between our variable in the shell structure, and SHLVL.
If SHLVL is 1, (env | grep SHLVL) will still print 1. Our variable in the shell structure would be 5 though.

@LeaYeh Just so you know, Elidjah tested this on Kamilla's evaluation.

I am closing this issue as not planned bc I cannot find any ressource to explain the following behavior (and Elidjah also had no clue):

bash-5.1$ export | grep SHLVL
2
bash-5.1$ env | grep SHLVL
1
bash-5.1$ echo $SHLVL
2

So it looks like SHLVL in env is always one lower.
However, calling the env exectuable in minishell does not confirm that it has anything to do with the env executable:

🌊rash$ env | grep SHLVL
1
🌊rash$ /bin/env | grep SHLVL
1