mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-15 04:32:24 +00:00
Decrease SHLVL before doing 'exec' from main shell
Problem: $ exec ksh $ echo $SHLVL 2 $ exec ksh $ echo $SHLVL 3 $ exec ksh $ echo $SHLVL 4 ...etc. SHLVL is supposed to acount the number of shell processes that you need to exit before you get logged out. Since ksh was replacing itself with a new shell in the same process using 'exec', SHLVL should not increase. src/cmd/ksh93/bltins/misc.c: b_exec(): - When about to replace the shell and we're not in a subshell, decrease SHLVL to cancel out a subsequent increase by the replacing shell. Bash and zsh also do this.
This commit is contained in:
parent
c828ea8d0d
commit
e5e1d4b53e
4 changed files with 15 additions and 3 deletions
4
NEWS
4
NEWS
|
@ -3,6 +3,10 @@ For full details, see the git log at: https://github.com/ksh93/ksh
|
|||
|
||||
Any uppercase BUG_* names are modernish shell bug IDs.
|
||||
|
||||
2021-05-18:
|
||||
|
||||
- Fixed SHLVL so that replacing ksh by itself (exec ksh) will not increase it.
|
||||
|
||||
2021-05-13:
|
||||
|
||||
- Fixed a bug with 'test -t 1' that was introduced on 2021-04-26:
|
||||
|
|
|
@ -161,6 +161,9 @@ int b_exec(int argc,char *argv[], Shbltin_t *context)
|
|||
if(job_close(logdata.sh) < 0)
|
||||
return(1);
|
||||
#endif /* JOBS */
|
||||
/* if the main shell is about to be replaced, decrease SHLVL to cancel out a subsequent increase */
|
||||
if(!shgd->realsubshell)
|
||||
(*SHLVL->nvalue.ip)--;
|
||||
/* force bad exec to terminate shell */
|
||||
pp = (struct checkpt*)logdata.sh->jmplist;
|
||||
pp->mode = SH_JMPEXIT;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
|
||||
#define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
|
||||
#define SH_RELEASE_DATE "2021-05-13" /* must be in this format for $((.sh.version)) */
|
||||
#define SH_RELEASE_DATE "2021-05-18" /* must be in this format for $((.sh.version)) */
|
||||
#define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK
|
||||
|
||||
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
|
||||
|
|
|
@ -1802,8 +1802,8 @@ be the value that was assigned plus the number of seconds since the assignment.
|
|||
.TP
|
||||
.SM
|
||||
.B SHLVL
|
||||
An integer variable the is incremented each time the shell
|
||||
is invoked and is exported.
|
||||
An integer variable that is incremented and exported
|
||||
each time the shell is invoked.
|
||||
If
|
||||
.SM
|
||||
.B SHLVL
|
||||
|
@ -6028,6 +6028,11 @@ is given,
|
|||
the command specified by
|
||||
the arguments is executed in place of this shell
|
||||
without creating a new process.
|
||||
The value of the
|
||||
.SM
|
||||
.B SHLVL
|
||||
environment variable is decreased by one,
|
||||
unless the shell replaced is a subshell.
|
||||
The
|
||||
.B \-c
|
||||
option causes the environment to be cleared before applying
|
||||
|
|
Loading…
Reference in a new issue