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

Make 'redirect' a regular builtin instead of an alias of 'exec'

This commit converts the redirect='command exec' alias to a regular
'redirect' builtin command that only accepts I/O redirections, which
persist as in 'exec'. This means that:
* 'unlias -a' no longer removes the 'redirect' command;
* users no longer accidentally get logged out of their shells if
  they type something intuitive but wrong, like 'redirect ls >file'.

This should not introduce any legitimate change in behaviour. If
someone did accidentally pass non-redirection arguments to
'redirect', unexpected behaviour would occur; this now produces
an 'incorrect syntax' error.

src/cmd/ksh93/bltins/misc.c: b_exec():
- Recognise 'redirect' when parsing options.
- If invoked as 'redirect', produce error if there are arguments.

src/cmd/ksh93/data/aliases.c:
- Remove redirect='command exec' alias.

src/cmd/ksh93/data/builtins.c:
- Update/improve comments re ordering.
- Add 'redirect' builtin entry.
- sh_optexec[]: Abbreviate redirection-related documentation;
  refer to redirect(1) instead.
- sh_optredirect[]: Add documentation.

src/cmd/ksh93/include/builtins.h:
- Add SYSREDIR parser ID, renumbering those following it.
- Improve comments.
- Add extern sh_optredirect[].

src/cmd/ksh93/sh.1:
- exec: Abbreviate redirection-related documentation; refer to
  'redirect' instead.
- redirect: Add documentation.

src/cmd/ksh93/sh/xec.c:
- Recognise SYSREDIR parser ID in addition to SYSEXEC when
  determining whether to make redirections persistent.

src/cmd/ksh93/tests/io.sh:
- To regress-test the new builtin, change most 'command exec' uses
  to 'redirect'.
- Add tests verifying the exit behaviour of 'exec', 'command exec',
  'redirect' on redirections.
This commit is contained in:
Martijn Dekker 2020-06-12 04:17:14 +02:00
parent 936802f92a
commit 7b82c338da
9 changed files with 134 additions and 75 deletions

View file

@ -804,8 +804,6 @@ but can be unset or redefined:
.TP
.B "r=\(fmhist \-s\(fm"
.TP
.B "redirect=\(fmcommand exec\(fm"
.TP
.B "source=\(fmcommand \s+2.\s-2\(fm"
.TP
.B "stop=\(fmkill \-s \s-1STOP\s+1\(fm"
@ -5802,10 +5800,11 @@ In addition, if
refers to a special built-in,
none of the special properties associated with the leading
daggers will be honored.
(For example, the predefined alias
.B "redirect=\(fmcommand exec\(fm"
(For example, using
.B "command set -o"
.I "option-name"
prevents a script from terminating when an invalid
redirection is given.)
option name is given.)
With the
.B \-x
option,
@ -5916,18 +5915,11 @@ rather than the first
to become
.B argv[0]
for the new process.
Input/output arguments may appear and
affect the current process.
If
.I arg\^
is not given,
the effect of this command is to
modify file descriptors
as prescribed by the input/output redirection list.
In this case,
any file descriptor numbers greater than 2 that are
opened with this mechanism are closed when invoking
another program.
is not given and only I/O redirection arguments are given,
then this command persistently modifies file descriptors as in
.BR redirect.
.TP
\(dg \f3exit\fP \*(OK \f2n\^\fP \*(CK
Causes the shell to exit
@ -6770,6 +6762,23 @@ by subsequent assignment.
When defining a type, if the value of a readonly sub-variable is not defined
the value is required when creating each instance.
.TP
\f3redirect\fP
This command only accepts input/output redirection arguments.
It can open and close files and modify file descriptors from
.B 0
to
.B 9
as specified by the input/output redirection list (see the
.I Input/Output\^
section above),
with the difference that the effect persists past the execution of the
.B redirect
command.
Any file descriptor numbers greater than
.B 2
that are opened with this mechanism are closed when invoking another program,
unless explicitly redirected to themselves as part of that invocation.
.TP
\(dg \f3return\fP \*(OK \f2n\^\fP \*(CK
Causes a shell
.I function