mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 11:42:21 +00:00
-o posix: inverse-sync braceexpand; properly sync letoctal
{Brace,expansion} is potentially incompatible with POSIX scripts,
because in POSIX those are simple literal strings with no special
meaning. So the POSIX option should really turn that off.
As of b301d417
, the 'posix' option was also forcing 'letoctal'
behaviour on, without actually setting that option. I've since
found that to be a botch; 'let' may recognise octals without that
option being set, and that looks like a bug.
So as of this commit, the '-o posix' option actually toggles both
of these options off/on and on/of, respectively. 'set +o posix'
toggles them inversely. However, it is now possible to control both
options (and their associated behaviour) independently in between
'set -o posix' and 'set +o posix'. Much better.
src/cmd/ksh93/sh/main.c: sh_main():
- If SH_POSIX was set on init, turn on SH_LETOCTAL by default
instead of SH_BRACEEXPAND.
src/cmd/ksh93/sh/args.c: sh_applyopts():
- Turn off SH_BRACEEXPAND and turn on SH_LETOCTAL when SH_POSIX is
turned on (but not if it was already on).
- Turn on SH_BRACEEXPAND and turn off SH_LETOCTAL when SH_POSIX is
turned off (but not if it was already off).
src/cmd/ksh93/sh/arith.c: arith():
- Revert to pre-b301d417 and only check SH_LETOCTAL option when
deciding whether 'let' should skip initial zeros.
src/cmd/ksh93/tests/options.sh:
- Update $- test to allow '-o posix' to switch B = braceexpand.
src/cmd/ksh93/sh.1:
- Update.
- Edit for clarity.
This commit is contained in:
parent
dc80f40d40
commit
f45a0f1650
7 changed files with 69 additions and 25 deletions
8
NEWS
8
NEWS
|
@ -3,6 +3,14 @@ For full details, see the git log at: https://github.com/ksh93/ksh
|
||||||
|
|
||||||
Any uppercase BUG_* names are modernish shell bug IDs.
|
Any uppercase BUG_* names are modernish shell bug IDs.
|
||||||
|
|
||||||
|
2020-09-18:
|
||||||
|
|
||||||
|
- Setting the 'posix' option now turns off the 'braceexpand' option, as brace
|
||||||
|
expansion is not specified by POSIX and potentially incompatible with sh
|
||||||
|
scripts. In addition, 'set -o posix' now turns on the 'letoctal' option
|
||||||
|
instead of controlling that behaviour directly. 'set +o posix' does the
|
||||||
|
reverse of these.
|
||||||
|
|
||||||
2020-09-17:
|
2020-09-17:
|
||||||
|
|
||||||
- In the vi and emacs line editors, repeat count parameters can now also be
|
- In the vi and emacs line editors, repeat count parameters can now also be
|
||||||
|
|
|
@ -17,4 +17,4 @@
|
||||||
* David Korn <dgk@research.att.com> *
|
* David Korn <dgk@research.att.com> *
|
||||||
* *
|
* *
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
#define SH_RELEASE "93u+m 2020-09-17"
|
#define SH_RELEASE "93u+m 2020-09-18"
|
||||||
|
|
|
@ -6370,12 +6370,10 @@ to be evaluated.
|
||||||
.B let
|
.B let
|
||||||
only recognizes octal constants starting with
|
only recognizes octal constants starting with
|
||||||
.B 0
|
.B 0
|
||||||
if one of the
|
when the
|
||||||
.B set
|
.B set
|
||||||
options
|
option
|
||||||
.B letoctal
|
.B letoctal
|
||||||
or
|
|
||||||
.B posix
|
|
||||||
is on.
|
is on.
|
||||||
See
|
See
|
||||||
.I "Arithmetic Evaluation"
|
.I "Arithmetic Evaluation"
|
||||||
|
@ -6906,7 +6904,8 @@ is used, the variable
|
||||||
is not unset first.
|
is not unset first.
|
||||||
.TP 8
|
.TP 8
|
||||||
.B \-B
|
.B \-B
|
||||||
Enable brace group expansion. On by default.
|
Enable brace group expansion. On by default, except
|
||||||
|
if ksh is invoked as \fBsh\fR, \fBrsh\fR, or \fBpfsh\fR.
|
||||||
.TP 8
|
.TP 8
|
||||||
.B \-C
|
.B \-C
|
||||||
Prevents redirection
|
Prevents redirection
|
||||||
|
@ -7034,8 +7033,7 @@ The
|
||||||
.B let
|
.B let
|
||||||
command allows octal constants starting with
|
command allows octal constants starting with
|
||||||
.BR 0 .
|
.BR 0 .
|
||||||
If the \fBposix\fR shell option is active,
|
On by default if ksh is invoked as \fBsh\fR, \fBrsh\fR, or \fBpfsh\fR.
|
||||||
octals are recognized regardless of this option.
|
|
||||||
.TP 8
|
.TP 8
|
||||||
.B markdirs
|
.B markdirs
|
||||||
All directory names resulting from file name generation have a trailing
|
All directory names resulting from file name generation have a trailing
|
||||||
|
@ -7081,16 +7079,37 @@ will be the value of the last non-zero command
|
||||||
to fail or zero if no command has failed.
|
to fail or zero if no command has failed.
|
||||||
.TP 8
|
.TP 8
|
||||||
.B posix
|
.B posix
|
||||||
Enable full POSIX standard compliance mode. This option
|
Enables the POSIX standard mode for maximum compatibility with other compliant
|
||||||
is on by default if ksh is invoked as \fBsh\fR, \fBrsh\fR, or \fBpfsh\fR. It
|
shells. At the moment that the \fBposix\fR option is turned on, it also turns
|
||||||
disables passing exported variables' attributes (such as integer or readonly) to a new ksh process through the environment,
|
on \fBletoctal\fR and turns off \fB\-B\fR/\fBbraceexpand\fR; the reverse is
|
||||||
causes file descriptors > 2 to be left open when invoking another program,
|
done when \fBposix\fR is turned back off. (These options can still be
|
||||||
makes the \fB<>\fR redirection operator default to standard input,
|
controlled independently in between.) Furthermore, the \fBposix\fR option
|
||||||
causes the \fBcommand\fR utility to disable declaration command properties of any declaration commands it invokes,
|
is automaticaly turned on upon invocation if ksh is invoked as \fBsh\fR,
|
||||||
skips the initialization of preset aliases upon invoking an interactive shell,
|
\fBrsh\fR, or \fBpfsh\fR. In that case, or if the option is turned on by
|
||||||
disables a hack that makes \fBtest -t\fR (\fB[ -t ]\fR) equivalent to \fBtest -t 1\fR (\fB[ -t 1 ]\fR),
|
specifying \fB-o posix\fR on the invocation command line, the invoked shell
|
||||||
enables octal numbers in \fBlet\fR shell arithmetic (see \fBletoctal\fR), and
|
will not set the preset aliases even if interactive, and will not import type
|
||||||
disables the \fB&>\fR redirection shorthand.
|
attributes for variables (such as integer or readonly) from the environment.
|
||||||
|
.RS 8
|
||||||
|
.PP
|
||||||
|
In addition, while on, the \fBposix\fR option
|
||||||
|
.IP \[bu] 3
|
||||||
|
disables exporting variable type attributes to the environment for other ksh
|
||||||
|
processes to import;
|
||||||
|
.IP \[bu]
|
||||||
|
causes file descriptors > 2 to be left open when invoking another program;
|
||||||
|
.IP \[bu]
|
||||||
|
disables the \fB&>\fR redirection shorthand;
|
||||||
|
.IP \[bu]
|
||||||
|
makes the \fB<>\fR redirection operator default to redirecting standard input
|
||||||
|
if no file descriptor number precedes it;
|
||||||
|
.IP \[bu]
|
||||||
|
causes the \fBcommand\fR utility to disable declaration command properties of
|
||||||
|
any declaration commands it invokes;
|
||||||
|
and
|
||||||
|
.IP \[bu]
|
||||||
|
disables a hack that makes \fBtest -t\fR (\fB[ -t ]\fR) equivalent to
|
||||||
|
\fBtest -t 1\fR (\fB[ -t 1 ]\fR).
|
||||||
|
.RE
|
||||||
.TP 8
|
.TP 8
|
||||||
.B privileged
|
.B privileged
|
||||||
Same as
|
Same as
|
||||||
|
|
|
@ -289,9 +289,7 @@ int sh_argopts(int argc,register char *argv[], void *context)
|
||||||
}
|
}
|
||||||
argc--;
|
argc--;
|
||||||
}
|
}
|
||||||
/* handling SH_INTERACTIVE and SH_PRIVILEGED has been moved to
|
/* SH_INTERACTIVE and SH_PRIVILEGED are handled in sh_applyopts() */
|
||||||
* sh_applyopts(), so that the code can be reused from b_shopt(), too
|
|
||||||
*/
|
|
||||||
sh_applyopts(ap->sh,newflags);
|
sh_applyopts(ap->sh,newflags);
|
||||||
#if SHOPT_KIA
|
#if SHOPT_KIA
|
||||||
if(ap->kiafile)
|
if(ap->kiafile)
|
||||||
|
@ -343,6 +341,21 @@ void sh_applyopts(Shell_t* shp,Shopt_t newflags)
|
||||||
(shp->gd->userid==shp->gd->euserid && shp->gd->groupid==shp->gd->egroupid))
|
(shp->gd->userid==shp->gd->euserid && shp->gd->groupid==shp->gd->egroupid))
|
||||||
off_option(&newflags,SH_PRIVILEGED);
|
off_option(&newflags,SH_PRIVILEGED);
|
||||||
}
|
}
|
||||||
|
/* -o posix also switches -o braceexpand and -o letoctal */
|
||||||
|
if(!sh_isoption(SH_POSIX) && is_option(&newflags,SH_POSIX))
|
||||||
|
{
|
||||||
|
#if SHOPT_BRACEPAT
|
||||||
|
off_option(&newflags,SH_BRACEEXPAND);
|
||||||
|
#endif
|
||||||
|
on_option(&newflags,SH_LETOCTAL);
|
||||||
|
}
|
||||||
|
else if(sh_isoption(SH_POSIX) && !is_option(&newflags,SH_POSIX))
|
||||||
|
{
|
||||||
|
#if SHOPT_BRACEPAT
|
||||||
|
on_option(&newflags,SH_BRACEEXPAND);
|
||||||
|
#endif
|
||||||
|
off_option(&newflags,SH_LETOCTAL);
|
||||||
|
}
|
||||||
shp->options = newflags;
|
shp->options = newflags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -390,10 +390,10 @@ static Sfdouble_t arith(const char **ptr, struct lval *lvalue, int type, Sfdoubl
|
||||||
char lastbase=0, *val = xp, oerrno = errno;
|
char lastbase=0, *val = xp, oerrno = errno;
|
||||||
lvalue->eflag = 0;
|
lvalue->eflag = 0;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if(shp->bltindata.bnode==SYSLET && !sh_isoption(SH_LETOCTAL) && !sh_isoption(SH_POSIX))
|
if(shp->bltindata.bnode==SYSLET && !sh_isoption(SH_LETOCTAL))
|
||||||
{ /*
|
{ /*
|
||||||
* Since we're running the "let" builtin, disable octal number processing by
|
* Since we're running the "let" builtin, disable octal number processing by
|
||||||
* skipping all initial zeros, unless the 'letoctal' or 'posix' option is on.
|
* skipping all initial zeros, unless the 'letoctal' option is on.
|
||||||
*/
|
*/
|
||||||
while(*val=='0' && isdigit(val[1]))
|
while(*val=='0' && isdigit(val[1]))
|
||||||
val++;
|
val++;
|
||||||
|
|
|
@ -157,8 +157,11 @@ int sh_main(int ac, char *av[], Shinit_f userinit)
|
||||||
nv_putval(PS4NOD,e_traceprompt,NV_RDONLY);
|
nv_putval(PS4NOD,e_traceprompt,NV_RDONLY);
|
||||||
path_pwd(shp,1);
|
path_pwd(shp,1);
|
||||||
iop = (Sfio_t*)0;
|
iop = (Sfio_t*)0;
|
||||||
|
if(sh_isoption(SH_POSIX))
|
||||||
|
sh_onoption(SH_LETOCTAL);
|
||||||
#if SHOPT_BRACEPAT
|
#if SHOPT_BRACEPAT
|
||||||
sh_onoption(SH_BRACEEXPAND);
|
else
|
||||||
|
sh_onoption(SH_BRACEEXPAND);
|
||||||
#endif
|
#endif
|
||||||
if((beenhere++)==0)
|
if((beenhere++)==0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -533,9 +533,10 @@ print $'alias print=:\nprint foobar' > dotfile
|
||||||
|
|
||||||
# ======
|
# ======
|
||||||
# test that '-o posix' option (not having a letter) does not affect "$-" expansion
|
# test that '-o posix' option (not having a letter) does not affect "$-" expansion
|
||||||
|
# other than B = braceexpand
|
||||||
(
|
(
|
||||||
command set +o posix 2>/dev/null
|
command set +o posix 2>/dev/null
|
||||||
opt1=$-
|
opt1=${-/B/}
|
||||||
command set -o posix 2>/dev/null
|
command set -o posix 2>/dev/null
|
||||||
opt2=$-
|
opt2=$-
|
||||||
[[ $opt1 == "$opt2" ]]
|
[[ $opt1 == "$opt2" ]]
|
||||||
|
|
Loading…
Reference in a new issue