Skip to content

Commit fa6a180

Browse files
committed
test/[: remove effectively inaccessible self-doc
Did you know that you could get a manual page for the 'test'/'[' builtin command using one of these strange command lines? test --man -- [ --man -- ] Neither did I. It's not documented or mentioned anywhere (and this syntax violates POSIX). So nobody knows about it, which makes that documentation useless. (The regular --man option doesn't work because that would break 'test'.) I only found out how to invoke it when I understood what the uncommented C code handling this does. The test/[ command's self-documentation is unmaintained since 2003 and somewhat incomplete. It's also mostly redundant with the documentation on Conditional Expressions in the main (k)sh.1 manual page. But unlike the latter, this is resident in RAM, wasting working memory in every shell process. src/cmd/ksh93/sh.1: - Add documentation for 'test'/'[' commands (yes, they were not mentioned in the main manual page until now), describing them in terms of differences from '[[' and recommending the latter. src/cmd/ksh93/include/test.h, src/cmd/ksh93/bltins/test.c, src/cmd/ksh93/data/testops.c: - Remove RAM-resident --man doc for test/[ command. - Remove the bizarre option parsing that allowed invoking it.
1 parent cd2cf23 commit fa6a180

File tree

4 files changed

+24
-119
lines changed

4 files changed

+24
-119
lines changed

src/cmd/ksh93/bltins/test.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,8 @@ int b_test(int argc, char *argv[],Shbltin_t *context)
202202
exitval = (*argv[2]!=0);
203203
goto done;
204204
}
205-
if(cp[0] != '-' || cp[2] || cp[1]=='?')
206-
{
207-
if(cp[0]=='-' && (cp[1]=='-' || cp[1]=='?') &&
208-
strcmp(argv[2],"--")==0)
209-
{
210-
char *av[3];
211-
av[0] = argv[0];
212-
av[1] = argv[1];
213-
av[2] = 0;
214-
optget(av,sh_opttest);
215-
errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
216-
return(2);
217-
}
205+
if(cp[0] != '-' || cp[2])
218206
break;
219-
}
220207
exitval = (!test_unop(tdata.sh,cp[1],argv[2]));
221208
goto done;
222209
case 2:

src/cmd/ksh93/data/testops.c

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -55,109 +55,6 @@ const Shtable_t shtab_testops[] =
5555
"", 0
5656
};
5757

58-
const char sh_opttest[] =
59-
"[-1c?\n@(#)$Id: test (AT&T Research) 2003-03-18 $\n]"
60-
USAGE_LICENSE
61-
"[+NAME?test - evaluate expression]"
62-
"[+DESCRIPTION?\btest\b evaluates expressions and indicates its "
63-
"results based on the exit status. Option parsing is not "
64-
"performed so that all arguments, including \b--\b are processed "
65-
" as operands. The evaluation of the "
66-
"expression depends on the number of operands as follows:]{"
67-
"[+0?Evaluates to false.]"
68-
"[+1?True if argument is not an empty string.]"
69-
"[+2?If first operand is \b!\b, the result is True if the second "
70-
"operand an empty string. Otherwise, it is evaluated "
71-
"as one of the unary expressions defined below. If the "
72-
"unary operator is invalid and the second argument is \b--\b,"
73-
"then the first argument is processed as an option argument.]"
74-
"[+3?If first operand is \b!\b, the result is True if the second "
75-
"and third operand evaluated as a unary expression is False. "
76-
"Otherwise, the three operands are evaluaged as one of the "
77-
"binary expressions listed below.]"
78-
"[+4?If first operand is \b!\b, the result is True if the next "
79-
"three operands are a valid binary expression that is False.]"
80-
"}"
81-
"[If any \afile\a is of the form \b/dev/fd/\b\an\a, then file descriptor "
82-
"\an\a is checked.]"
83-
"[+?Unary expressions can be one of the following:]{"
84-
"[+-a \afile\a?True if \afile\a exists, obsolete.]"
85-
"[+-b \afile\a?True if \afile\a exists and is a block special file.]"
86-
"[+-c \afile\a?True if \afile\a exists and is a character special "
87-
"file.]"
88-
"[+-d \afile\a?True if \afile\a exists and is a directory.]"
89-
"[+-e \afile\a?True if \afile\a exists.]"
90-
"[+-f \afile\a?True if \afile\a exists and is a regular file.]"
91-
"[+-g \afile\a?True if \afile\a exists and has its set-group-id bit "
92-
"set.]"
93-
"[+-h \afile\a?True if \afile\a exists and is a symbolic link.]"
94-
"[+-k \afile\a?True if \afile\a exists and has its sticky bit on.]"
95-
#if SHOPT_TEST_L
96-
"[+-l \afile\a?True if \afile\a exists and is a symbolic link.]"
97-
#endif
98-
"[+-n \astring\a?True if length of \astring\a is non-zero.]"
99-
"[+-o \aoption\a?True if the shell option \aoption\a is enabled.]"
100-
"[+-p \afile\a?True if \afile\a exists and is a pipe or fifo.]"
101-
"[+-r \afile\a?True if \afile\a exists and is readable.]"
102-
"[+-s \afile\a?True if \afile\a exists and has size > 0.]"
103-
"[+-t \afildes\a?True if file descriptor number \afildes\a is "
104-
"open and is associated with a terminal device.]"
105-
"[+-u \afile\a?True if \afile\a exists and has its set-user-id bit "
106-
"set.]"
107-
"[+-v \avarname\a?True if \avarname\a is a valid variable name that is set.]"
108-
"[+-w \afile\a?True if \afile\a exists and is writable.]"
109-
"[+-x \afile\a?True if \afile\a exists and is executable. For a "
110-
"directory it means that it can be searched.]"
111-
"[+-z \astring\a?True if \astring\a is a zero length string.]"
112-
"[+-G \afile\a?True if \afile\a exists and group is the effective "
113-
"group id of the current process.]"
114-
"[+-L \afile\a?True if \afile\a exists and is a symbolic link.]"
115-
"[+-N \afile\a?True if \afile\a exists and has been modified since "
116-
"it was last read.]"
117-
"[+-O \afile\a?True if \afile\a exists and owner is the effective "
118-
"user id of the current process.]"
119-
"[+-R \avarname\a?True if \avarname\a is a name reference.]"
120-
"[+-S \afile\a?True if \afile\a exists and is a socket.]"
121-
"}"
122-
"[+?Binary expressions can be one of the following:]{"
123-
"[+\astring1\a = \astring2\a?True if \astring1\a is equal to "
124-
"\astring2\a.]"
125-
"[+\astring1\a == \astring2\a?True if \astring1\a is equal to "
126-
"\astring2\a.]"
127-
"[+\astring1\a != \astring2\a?True if \astring1\a is not equal to "
128-
"\astring2\a.]"
129-
"[+\anum1\a -eq \anum2\a?True if numerical value of \anum1\a is "
130-
"equal to \anum2\a.]"
131-
"[+\anum1\a -ne \anum2\a?True if numerical value of \anum1\a is not "
132-
"equal to \anum2\a.]"
133-
"[+\anum1\a -lt \anum2\a?True if numerical value of \anum1\a is less "
134-
"than \anum2\a.]"
135-
"[+\anum1\a -le \anum2\a?True if numerical value of \anum1\a is less "
136-
"than or equal to \anum2\a.]"
137-
"[+\anum1\a -gt \anum2\a?True if numerical value of \anum1\a is "
138-
"greater than \anum2\a.]"
139-
"[+\anum1\a -ge \anum2\a?True if numerical value of \anum1\a is "
140-
"greater than or equal to \anum2\a.]"
141-
"[+\afile1\a -nt \afile2\a?True if \afile1\a is newer than \afile2\a "
142-
"or \afile2\a does not exist.]"
143-
"[+\afile1\a -ot \afile2\a?True if \afile1\a is older than \afile2\a "
144-
"or \afile2\a does not exist.]"
145-
"[+\afile1\a -ef \afile2\a?True if \afile1\a is another name for "
146-
"\afile2\a. This will be true if \afile1\a is a hard link "
147-
"or a symbolic link to \afile2\a.]"
148-
"}"
149-
"\n"
150-
"\n[expression]\n"
151-
"\n"
152-
"[+EXIT STATUS?]{"
153-
"[+0?Indicates that the specified expression is True.]"
154-
"[+1?Indicates that the specified expression is False.]"
155-
"[+>1?An error occurred.]"
156-
"}"
157-
158-
"[+SEE ALSO?\blet\b(1), \bexpr\b(1)]"
159-
;
160-
16158
const char test_opchars[] = "HLNRSVOGCaeohrwxdcbfugkv"
16259
#if SHOPT_TEST_L
16360
"l"

src/cmd/ksh93/include/test.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ extern int test_unop(Shell_t*,int, const char*);
6161
extern int test_inode(const char*, const char*);
6262
extern int test_binop(Shell_t*,int, const char*, const char*);
6363

64-
extern const char sh_opttest[];
6564
extern const char test_opchars[];
6665
extern const char e_argument[];
6766
extern const char e_missing[];

src/cmd/ksh93/sh.1

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5494,7 +5494,7 @@ The command only expands parameters.
54945494
.br
54955495
.ne 2
54965496
.TP
5497-
\(dg \f3\|. \f2name\^\fP \*(OK \f2arg\^\fP .\|.\|. \*(CK
5497+
\(dg \f3\|.\fP \f2name\^\fP \*(OK \f2arg\^\fP .\|.\|. \*(CK
54985498
If
54995499
.I name\^
55005500
is a function defined with the
@@ -5525,6 +5525,10 @@ command and the original positional parameters are restored upon completion.
55255525
Otherwise the positional parameters are unchanged.
55265526
The exit status is the exit status of the last command executed.
55275527
.TP
5528+
\f3[\fP \f2expression\fP \f3]\fP
5529+
The \f3[\fP command is the same as \f3test\fP, with the exception that an
5530+
additional closing \f3]\fP argument is required. See \f3test\fP below.
5531+
.TP
55285532
\f3alias\fP \*(OK \f3\-ptx\fP \*(CK \*(OK \f2name\fP\*(OK \f3=\fP\f2value\^\fP \*(CK \*(CK .\|.\|.
55295533
.B alias\^
55305534
with no arguments prints the list of aliases
@@ -7198,6 +7202,24 @@ in the parent shell). Equivalent to
71987202
.BR kill\ -s\ STOP\ "$$" ,
71997203
except that it accepts no operands and refuses to suspend a login shell.
72007204
.TP
7205+
\f3test\fP \f2expression\fP
7206+
The \f3test\fP and \f3[\fP commands execute conditional expressions similar
7207+
to those specified for the \f3[[\fP compound command under
7208+
.I Conditional Expressions
7209+
above, but with several important differences. The \f3=\fP, \f3==\fP and
7210+
\f3!=\fP operators test for string (in)equality without pattern matching;
7211+
the \f3==\fP variant is nonstandard and should not be used. The \f3=\(ap\fP,
7212+
\f3<\fP, \f3>\fP, \f3&&\fP and \f3||\fP operators are not available. Most
7213+
importantly, as \f3test\fP and \f3[\fP are simple regular commands, field
7214+
splitting and file name generation \f2are\fP performed on all their
7215+
arguments and all aspects of regular shell grammar (such as redirection)
7216+
remain active. This is usually harmful, so care must be taken to quote
7217+
arguments and expansions to avoid this. There are also certain inherent
7218+
grammatical ambiguities in the expressions. To avoid the many pitfalls
7219+
arising from these issues, the \f3[[\fP compound command should be used
7220+
instead. The primary purpose of the \f3test\fP and \f3[\fP commands is
7221+
compatibility with other shells that lack \f3[[\fP.
7222+
.TP
72017223
\f3times\fP
72027224
Displays the accumulated user and system CPU times, one line with the times
72037225
used by the shell and another with those used by all of the shell's child

0 commit comments

Comments
 (0)