• [^] # Re: mais il reste un problème

    Posté par (site web personnel) . En réponse au message environnement non transmis par variable environ. Évalué à 4.

    Les mêmes causes produisent les mêmes effets :

    $ echo $SHLVL
    1
    $ ./exemple-execve
    2
    $ bash
    $ ./exemple-execve
    3
    $ sh
    $ ./exemple-execve
    3
    $ exit
    exit
    $ exit
    exit
    $ ./exemple-execve
    2
    for shell in /bin/sh /bin/dash /bin/bash /bin/mksh /bin/mksh-static /usr/bin/tmux /bin/zsh /usr/bin/zsh ; do echo $SHLVL ; echo "avant $shell" ; $shell -c "./exemple-execve ; exit" ; echo "après $shell" ; done ; echo $SHLVL
    1
    avant /bin/sh
    2
    après /bin/sh
    1
    avant /bin/dash
    2
    après /bin/dash
    1
    avant /bin/bash
    3
    après /bin/bash
    1
    avant /bin/mksh
    2
    après /bin/mksh
    1
    avant /bin/mksh-static
    2
    après /bin/mksh-static
    1
    avant /usr/bin/tmux
    3
    après /usr/bin/tmux
    1
    avant /bin/zsh
    3
    après /bin/zsh
    1
    avant /usr/bin/zsh
    3
    après /usr/bin/zsh
    1

    Quels shells se préoccupent de la variable SHLVL (visiblement bash et zsh au moins) ?

    $ for shell in /bin/sh /bin/dash /bin/bash /bin/mksh /bin/mksh-static /usr/bin/tmux /bin/zsh /usr/bin/zsh ; do grep -H -c SHLVL $shell ; done
    /bin/sh:0
    /bin/dash:0
    /bin/bash:1
    /bin/mksh:0
    /bin/mksh-static:0
    /usr/bin/tmux:0
    /bin/zsh:1
    /usr/bin/zsh:1
    $ for shell in /bin/bash /bin/zsh ; do echo $shell ; strings $shell|grep SHLVL ; done
    /bin/bash
    SHLVL
    /bin/zsh
    SHLVL
    

    Et les pages de manuel :

    man bash
     SHLVL Incrémenté de 1 à chaque appel d'une instance de bash.
    man zshparam
     SHLVL <S>
     Incremented by one each time a new shell is started.