From 4f9456d69f66c2d93c752b119ac322a0e61870c5 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Thu, 9 Jun 2022 21:50:26 +0100 Subject: [PATCH] posix: re-allow preset aliases on interactive (re: ddaa145b) The POSIX standard in fact contains a sentence that specifically allows preset aliases: "Implementations also may provide predefined valid aliases that are in effect when the shell is invoked." https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_03_01 I had missed that back then. It's still a terrible idea for scripts (particularly the way 93u+ implemented them), but for interactive POSIX shells it makes a lot more sense and does not violate POSIX. src/cmd/ksh93/sh/main.c: sh_main(): - Preset aliases for interactive shell regardless of SH_POSIX. --- NEWS | 3 +++ src/cmd/ksh93/sh.1 | 11 +++-------- src/cmd/ksh93/sh/main.c | 9 +++------ 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/NEWS b/NEWS index b6d7f7a8c..7223a2e66 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,9 @@ Any uppercase BUG_* names are modernish shell bug IDs. <##pattern redirection operators will not work and the -n option to the read built-in will not return early when reading from a slow device.) +- An interactive shell initialized in POSIX mode now once again has the + preset aliases defined. This amends a change made on 2020-09-11. + 2022-06-08: - If -B/--braceexpand is turned on in --posix mode, it now only allows brace diff --git a/src/cmd/ksh93/sh.1 b/src/cmd/ksh93/sh.1 index 7557a9481..361308e49 100644 --- a/src/cmd/ksh93/sh.1 +++ b/src/cmd/ksh93/sh.1 @@ -811,11 +811,7 @@ 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). +when the shell is invoked as an interactive shell. Preset aliases can be unset or redefined. .RS 20 .PD 0 @@ -7700,9 +7696,8 @@ is automatically turned on upon invocation if the shell is invoked as \fBsh\fR or \fBrsh\fR, or if \fB\-o posix\fR or \fB\-\-posix\fR is specified on the shell invocation command line, or when executing scripts without a \fB#!\fR path with this option active in the invoking shell. In that case, the invoked shell -will not set the preset aliases even if interactive, and will not import type -attributes for variables (such as integer or left/right justify) -from the environment. +will not import type attributes for variables (such as integer or left/right +justify) from the environment. .RS 8 .PP In addition, while on, the \fBposix\fR option diff --git a/src/cmd/ksh93/sh/main.c b/src/cmd/ksh93/sh/main.c index 5d2c20e0b..065f6d85c 100644 --- a/src/cmd/ksh93/sh/main.c +++ b/src/cmd/ksh93/sh/main.c @@ -166,12 +166,9 @@ int sh_main(int ac, char *av[], Shinit_f userinit) { sh_onoption(SH_BGNICE); sh_onoption(SH_RC); - if(!sh_isoption(SH_POSIX)) - { - /* preset aliases for interactive non-POSIX ksh */ - dtclose(sh.alias_tree); - sh.alias_tree = sh_inittree(shtab_aliases); - } + /* preset aliases for interactive ksh/sh */ + dtclose(sh.alias_tree); + sh.alias_tree = sh_inittree(shtab_aliases); } #if SHOPT_REMOTE /*