1 This file is test.def, from which is created test.c.
2 It implements the builtin "test" in Bash.
4 Copyright (C) 1987-2009 Free Software Foundation, Inc.
6 This file is part of GNU Bash, the Bourne Again SHell.
8 Bash is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 Bash is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Bash. If not, see <http://www.gnu.org/licenses/>.
24 $FUNCTION test_builtin
25 $SHORT_DOC test [expr]
26 Evaluate conditional expression.
28 Exits with a status of 0 (true) or 1 (false) depending on
29 the evaluation of EXPR. Expressions may be unary or binary. Unary
30 expressions are often used to examine the status of a file. There
31 are string operators as well, and numeric comparison operators.
35 -a FILE True if file exists.
36 -b FILE True if file is block special.
37 -c FILE True if file is character special.
38 -d FILE True if file is a directory.
39 -e FILE True if file exists.
40 -f FILE True if file exists and is a regular file.
41 -g FILE True if file is set-group-id.
42 -h FILE True if file is a symbolic link.
43 -L FILE True if file is a symbolic link.
44 -k FILE True if file has its `sticky' bit set.
45 -p FILE True if file is a named pipe.
46 -r FILE True if file is readable by you.
47 -s FILE True if file exists and is not empty.
48 -S FILE True if file is a socket.
49 -t FD True if FD is opened on a terminal.
50 -u FILE True if the file is set-user-id.
51 -w FILE True if the file is writable by you.
52 -x FILE True if the file is executable by you.
53 -O FILE True if the file is effectively owned by you.
54 -G FILE True if the file is effectively owned by your group.
55 -N FILE True if the file has been modified since it was last read.
57 FILE1 -nt FILE2 True if file1 is newer than file2 (according to
60 FILE1 -ot FILE2 True if file1 is older than file2.
62 FILE1 -ef FILE2 True if file1 is a hard link to file2.
66 -z STRING True if string is empty.
69 STRING True if string is not empty.
72 True if the strings are equal.
74 True if the strings are not equal.
76 True if STRING1 sorts before STRING2 lexicographically.
78 True if STRING1 sorts after STRING2 lexicographically.
82 -o OPTION True if the shell option OPTION is enabled.
83 ! EXPR True if expr is false.
84 EXPR1 -a EXPR2 True if both expr1 AND expr2 are true.
85 EXPR1 -o EXPR2 True if either expr1 OR expr2 is true.
87 arg1 OP arg2 Arithmetic tests. OP is one of -eq, -ne,
88 -lt, -le, -gt, or -ge.
90 Arithmetic binary operators return true if ARG1 is equal, not-equal,
91 less-than, less-than-or-equal, greater-than, or greater-than-or-equal
95 Returns success if EXPR evaluates to true; fails if EXPR evaluates to
96 false or an invalid argument is given.
100 $DOCNAME test_bracket
101 $FUNCTION test_builtin
102 $SHORT_DOC [ arg... ]
103 Evaluate conditional expression.
105 This is a synonym for the "test" builtin, but the last argument must
106 be a literal `]', to match the opening `['.
111 #if defined (HAVE_UNISTD_H)
113 # include <sys/types.h>
118 #include "../bashansi.h"
119 #include "../bashintl.h"
121 #include "../shell.h"
125 extern char *this_command_name;
127 /* TEST/[ builtin. */
135 /* We let Matthew Bradburn and Kevin Braunsdorf's code do the
136 actual test command. So turn the list of args into an array
137 of strings, since that is what their code wants. */
140 if (this_command_name[0] == '[' && !this_command_name[1])
142 builtin_error (_("missing `]'"));
143 return (EX_BADUSAGE);
146 return (EXECUTION_FAILURE);
149 argv = make_builtin_argv (list, &argc);
150 result = test_command (argc, argv);