Skip to content

Commit 61d9bca

Browse files
committed
POSIX compliance: rm harmful default aliases 'command '/'nohup '
Continuing alias substitution after 'command' (due to the final space in the alias) is inherently broken and doing so by default is incompatible with the POSIX standard, as aliases may contain arbitrary shell grammar. For instance, until the previous commit, the POSIX standard 'times' command was an alias: times='{ { time;} 2>&1;}' -- and so, of course, 'command times' gave a syntax error, although this is a perfectly valid POSIX idiom that must be supported. 'command' is specified by POSIX as a regular builtin, not an alias. Therefore it should always bypass aliases just as it bypasses functions to expose standard builtin and external commands. I can only imagine that the reason for this command='command ' alias was that some standard commands themselves were implemented as aliases, and POSIX requires that standard commands are accessible with the 'command' prefix. But implementing standard commands as aliases is itself inherently broken. It never worked for 'command times', as shown; and in any case, removing all aliases with 'unalias -a' should not get rid of standard commands. Similarly, the default alias nohup='nohup ' is also harmful. Anyone who really wants to keep this behaviour can just define these aliases themselves in their script or ~/.kshrc file. src/cmd/ksh93/data/aliases.c: - Remove default alias command='command '. - Remove default alias nohup='nohup '. src/cmd/ksh93/sh.1 - Remove the above default aliases from the list. - Mention that the 'command' builtin does not search for aliases. (cherry picked from commit 5cfe7c4e2015b7445da24983af5008035c4b6e1e)
1 parent 65d363f commit 61d9bca

File tree

4 files changed

+7
-27
lines changed

4 files changed

+7
-27
lines changed

NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ Any uppercase BUG_* names are modernish shell bug IDs.
1212
another with those used by all of the shell's child processes.
1313
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_27
1414

15+
- The default aliases command='command ' and nohup='nohup ' have been
16+
removed because they caused breakage in an attempt to circumvent other
17+
breakage which is being fixed. In the unlikely even that anyone still
18+
needs alias substitution to continue on the command argument following
19+
'command' or 'nohup', it's easy to set these aliases yourself.
20+
1521
2020-06-05:
1622

1723
- Fix a bug that caused special variables such as PATH, LANG, LC_ALL,

TODO

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,9 @@ Fix build failures:
1010

1111
- ksh does not currently build on AIX, HP-UX, Solaris, or QNX.
1212

13-
______
14-
Remove hack for 'test -t' with no args == 'test -t 1':
15-
- from sh/parse.c, qscan()
16-
- from bltins/test.c
17-
1813
______
1914
Fix or remove broken default aliases:
2015

21-
- Remove alias times='{ { time;} 2>&1;}' which does not produce POSIX-
22-
compliant output; reimplement as a proper POSIX-compliant builtin.
23-
In any case, implementing a standard utility as an alias is unacceptable
24-
as 'unalias -a' (remove all aliases) should not remove standard utilities!
25-
Backport the builtin from the abandoned Vashisht/Rader branch:
26-
https://github.com/att/ast/pull/1332
27-
28-
- Remove alias command='command '. Continuing alias substitution after
29-
'command' (due to the final space in the alias) is inherently broken, as
30-
aliases may contain arbitrary shell grammar. For instance, when combining
31-
this default alias with the default 'times' alias ('command times'), which
32-
is perfectly valid per POSIX, you get a syntax error!
33-
34-
- Remove alias nohup='nohup '. Same reason as for 'command ' above.
35-
3616
- Remove pointless default aliases 'fc' and 'type'; these are already
3717
implemented as normal shell builtins. Add man page entries for these.
3818

src/cmd/ksh93/data/aliases.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const struct shtable2 shtab_aliases[] =
3333
"2d", NV_NOFREE, "set -f;_2d",
3434
#endif /* SHOPT_FS_3D */
3535
"autoload", NV_NOFREE, "typeset -fu",
36-
"command", NV_NOFREE, "command ",
3736
"compound", NV_NOFREE|BLT_DCL, "typeset -C",
3837
"fc", NV_NOFREE, "hist",
3938
"float", NV_NOFREE|BLT_DCL, "typeset -lE",
@@ -42,7 +41,6 @@ const struct shtable2 shtab_aliases[] =
4241
"history", NV_NOFREE, "hist -l",
4342
"integer", NV_NOFREE|BLT_DCL, "typeset -li",
4443
"nameref", NV_NOFREE|BLT_DCL, "typeset -n",
45-
"nohup", NV_NOFREE, "nohup ",
4644
"r", NV_NOFREE, "hist -s",
4745
"redirect", NV_NOFREE, "command exec",
4846
"source", NV_NOFREE, "command .",

src/cmd/ksh93/sh.1

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,6 @@ but can be unset or redefined:
790790
.TP
791791
.B "autoload=\(fmtypeset \-fu\(fm"
792792
.TP
793-
.B "command=\(fmcommand \(fm"
794-
.TP
795793
.B "compound=\(fmtypeset \-C\(fm"
796794
.TP
797795
.B "fc=hist"
@@ -808,8 +806,6 @@ but can be unset or redefined:
808806
.TP
809807
.B "nameref=\(fmtypeset \-n\(fm"
810808
.TP
811-
.B "nohup=\(fmnohup \(fm"
812-
.TP
813809
.B "r=\(fmhist \-s\(fm"
814810
.TP
815811
.B "redirect=\(fmcommand exec\(fm"
@@ -5811,7 +5807,7 @@ the operating system's standard utilities path
58115807
rather than the one defined by the value of
58125808
.SM
58135809
.BR PATH .
5814-
Functions will not be searched for when finding
5810+
Functions and aliases will not be searched for when finding
58155811
.IR name .
58165812
In addition, if
58175813
.I name\^

0 commit comments

Comments
 (0)