1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Reinstate 'r' and 'history' as preset aliases for interactive ksh

Following a community discussion, it became clear that 'r' is
particularly problematic as a regular builtin, as the name can and
does conflict with at least one legit external command by that
name. There was a consensus against removing it altogether and
letting users set the alias in their login scripts. However,
aliases are easier to bypass, remove or rename than builtins are.
My compromise is to reinstate 'r' as a preset alias on interactive
shells only, along with 'history', as was done in 17f81ebe before
they were converted to builtins in 03224ae3. So this reintroduces
the notion of predefined aliases to ksh 93u+m, but only for
interactive shells that are not initialised in POSIX mode.

src/cmd/ksh93/Makefile,
src/cmd/ksh93/Mamfile,
src/cmd/ksh93/include/shtable.h,
src/cmd/ksh93/data/aliases.c:
- Restore aliases.c containing shtab_aliases[], a table specifying
  the preset aliases.

src/cmd/ksh93/include/shtable.h,
src/cmd/ksh93/sh/init.c:
- Rename inittree() to sh_inittree() and make it extern, because we
  need to use it in main.c (sh_main()).

src/cmd/ksh93/sh/main.c: sh_main():
- Init preset aliases from shtab_aliases[] only if the shell is
  interactive and not in POSIX mode.

src/cmd/ksh93/bltins/typeset.c,
src/cmd/ksh93/tests/alias.sh:
- unall(): When unsetting an alias, pass on the NV_NOFREE attribute
  to nv_delete() to avoid an erroneous attempt to free a preset
  alias from read-only memory. See: 5d50f825

src/cmd/ksh93/data/builtins.c:
- Remove "history" and "r" entries from shtab_builtins[].
- Revert changes to inline fc/hist docs in sh_opthist[].

src/cmd/ksh93/bltins/hist.c: b_hist():
- Remove handling for 'history' and 'r' as builtins.

src/cmd/ksh93/sh.1:
- Update accordingly.

Resolves: https://github.com/ksh93/ksh/issues/125
This commit is contained in:
Martijn Dekker 2020-09-11 20:51:35 +02:00
parent 777dfa3e59
commit ddaa145b3d
12 changed files with 90 additions and 37 deletions

View file

@ -782,6 +782,20 @@ the
.B alias
definition command has to be executed before
the command which references the alias is read.
.PP
The following aliases are automatically preset
when the shell is invoked as an interactive shell,
unless invoked in POSIX compliance mode
(see
.I Invocation\^
below).
Preset aliases can be unset or redefined.
.RS 20
.PD 0
.TP
.B "history=\(fmhist \-l\(fm"
.TP
.B "r=\(fmhist \-s\(fm"
.PD
.RE
.SS Tilde Substitution.
@ -4370,9 +4384,9 @@ to re-execute the command.
In this case a substitution parameter of the form
\f2old\fP\f3=\fP\f2new\fP
can be used to modify the command before execution.
For example, with the builtin
For example, with the preset alias
.BR r ,
which is functionally equivalent to
which is aliased to
.BR "\(fmhist \-s\(fm" ,
typing
`\f3r bad=good c\fP'
@ -6239,11 +6253,6 @@ to start
.I num
commands back.
.TP
\f3history\fP \*(OK \f3\-N\fP \f2num\^\fP \*(CK \*(OK \f3\-nr\^\fP \*(CK \*(OK \f2first\^\fP \*(OK \f2last\^\fP \*(CK \*(CK
Lists commands in the history file.
The same as
.BR hist\ \-l .
.TP
\(dd \f3integer\fP \f2vname\fP\*(OK\f3=\fP\f2value\^\fP\*(CK .\|.\|.
Declares each \f2vname\fP to be a long integer number.
The same as
@ -6659,11 +6668,6 @@ or
on the command line
determines which method is used.
.TP
\f3r\fP \*(OK \f2old\fP\f3\=\fP\f2new\^\fP \*(CK \*(OK \f2command\^\fP \*(CK
Reexecutes a command in the history file.
The same as
.BR hist\ \-s .
.TP
\f3read\fP \*(OK \f3\-ACSprsv\^\fP \*(CK \*(OK \f3\-d\fP \f2delim \^\fP\*(CK \*(OK \f3\-n\fP \f2n \^\fP\*(CK \*(OK \*(OK \f3\-N\fP \f2n \^\fP\*(CK \*(OK \f3\-t\fP \f2timeout \^\fP\*(CK \*(OK \f3\-u\fP \f2unit \^\fP\*(CK \*(OK \f2vname\f3?\f2prompt\^\f1 \*(CK \*(OK \f2vname\^\fP .\|.\|. \*(CK
The shell input mechanism.
One line is read and
@ -7059,6 +7063,7 @@ disables passing exported variables' attributes (such as integer or readonly) to
causes file descriptors > 2 to be left open when invoking another program,
makes the \fB<>\fR redirection operator default to standard input,
causes the \fBcommand\fR utility to disable declaration command properties of any declaration commands it invokes,
skips the initialization of preset aliases upon invoking an interactive shell,
disables a hack that makes \fBtest -t\fR (\fB[ -t ]\fR) equivalent to \fBtest -t 1\fR (\fB[ -t 1 ]\fR),
enables octal numbers in \fBlet\fR shell arithmetic (see \fBletoctal\fR), and
disables the \fB&>\fR redirection shorthand.