1.\"- 2.\" Copyright (c) 1991, 1993 3.\" The Regents of the University of California. All rights reserved. 4.\" 5.\" This code is derived from software contributed to Berkeley by 6.\" the Institute of Electrical and Electronics Engineers, Inc. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)test.1 8.1 (Berkeley) 5/31/93 33.\" $FreeBSD$ 34.\" 35.Dd July 3, 2004 36.Dt TEST 1 37.Os 38.Sh NAME 39.Nm test , 40.Nm \&[ 41.Nd condition evaluation utility 42.Sh SYNOPSIS 43.Nm 44.Ar expression 45.Nm \&[ 46.Ar expression Cm ] 47.Sh DESCRIPTION 48The 49.Nm 50utility evaluates the expression and, if it evaluates 51to true, returns a zero (true) exit status; otherwise 52it returns 1 (false). 53If there is no expression, test also 54returns 1 (false). 55.Pp 56All operators and flags are separate arguments to the 57.Nm 58utility. 59.Pp 60The following primaries are used to construct expression: 61.Bl -tag -width Ar 62.It Fl b Ar file 63True if 64.Ar file 65exists and is a block special 66file. 67.It Fl c Ar file 68True if 69.Ar file 70exists and is a character 71special file. 72.It Fl d Ar file 73True if 74.Ar file 75exists and is a directory. 76.It Fl e Ar file 77True if 78.Ar file 79exists (regardless of type). 80.It Fl f Ar file 81True if 82.Ar file 83exists and is a regular file. 84.It Fl g Ar file 85True if 86.Ar file 87exists and its set group ID flag 88is set. 89.It Fl h Ar file 90True if 91.Ar file 92exists and is a symbolic link. 93This operator is retained for compatibility with previous versions of 94this program. 95Do not rely on its existence; use 96.Fl L 97instead. 98.It Fl k Ar file 99True if 100.Ar file 101exists and its sticky bit is set. 102.It Fl n Ar string 103True if the length of 104.Ar string 105is nonzero. 106.It Fl p Ar file 107True if 108.Ar file 109is a named pipe 110.Pq Tn FIFO . 111.It Fl r Ar file 112True if 113.Ar file 114exists and is readable. 115.It Fl s Ar file 116True if 117.Ar file 118exists and has a size greater 119than zero. 120.It Fl t Ar file_descriptor 121True if the file whose file descriptor number 122is 123.Ar file_descriptor 124is open and is associated with a terminal. 125.It Fl u Ar file 126True if 127.Ar file 128exists and its set user ID flag 129is set. 130.It Fl w Ar file 131True if 132.Ar file 133exists and is writable. 134True 135indicates only that the write flag is on. 136The file is not writable on a read-only file 137system even if this test indicates true. 138.It Fl x Ar file 139True if 140.Ar file 141exists and is executable. 142True 143indicates only that the execute flag is on. 144If 145.Ar file 146is a directory, true indicates that 147.Ar file 148can be searched. 149.It Fl z Ar string 150True if the length of 151.Ar string 152is zero. 153.It Fl L Ar file 154True if 155.Ar file 156exists and is a symbolic link. 157.It Fl O Ar file 158True if 159.Ar file 160exists and its owner matches the effective user id of this process. 161.It Fl G Ar file 162True if 163.Ar file 164exists and its group matches the effective group id of this process. 165.It Fl S Ar file 166True if 167.Ar file 168exists and is a socket. 169.It Ar file1 Fl nt Ar file2 170True if 171.Ar file1 172exists and is newer than 173.Ar file2 . 174.It Ar file1 Fl ot Ar file2 175True if 176.Ar file1 177exists and is older than 178.Ar file2 . 179.It Ar file1 Fl ef Ar file2 180True if 181.Ar file1 182and 183.Ar file2 184exist and refer to the same file. 185.It Ar string 186True if 187.Ar string 188is not the null 189string. 190.It Ar \&s\&1 Cm \&= Ar \&s\&2 191True if the strings 192.Ar \&s\&1 193and 194.Ar \&s\&2 195are identical. 196.It Ar \&s\&1 Cm \&!= Ar \&s\&2 197True if the strings 198.Ar \&s\&1 199and 200.Ar \&s\&2 201are not identical. 202.It Ar \&s\&1 Cm \&< Ar \&s\&2 203True if string 204.Ar \&s\&1 205comes before 206.Ar \&s\&2 207based on the binary value of their characters. 208.It Ar \&s\&1 Cm \&> Ar \&s\&2 209True if string 210.Ar \&s\&1 211comes after 212.Ar \&s\&2 213based on the binary value of their characters. 214.It Ar \&n\&1 Fl \&eq Ar \&n\&2 215True if the integers 216.Ar \&n\&1 217and 218.Ar \&n\&2 219are algebraically 220equal. 221.It Ar \&n\&1 Fl \&ne Ar \&n\&2 222True if the integers 223.Ar \&n\&1 224and 225.Ar \&n\&2 226are not 227algebraically equal. 228.It Ar \&n\&1 Fl \> Ar \&n\&2 229True if the integer 230.Ar \&n\&1 231is algebraically 232greater than the integer 233.Ar \&n\&2 . 234.It Ar \&n\&1 Fl \&ge Ar \&n\&2 235True if the integer 236.Ar \&n\&1 237is algebraically 238greater than or equal to the integer 239.Ar \&n\&2 . 240.It Ar \&n\&1 Fl \< Ar \&n\&2 241True if the integer 242.Ar \&n\&1 243is algebraically less 244than the integer 245.Ar \&n\&2 . 246.It Ar \&n\&1 Fl \&le Ar \&n\&2 247True if the integer 248.Ar \&n\&1 249is algebraically less 250than or equal to the integer 251.Ar \&n\&2 . 252.El 253.Pp 254If 255.Ar file 256is a symbolic link, 257.Nm 258will fully dereference it and then evaluate the expression 259against the file referenced, except for the 260.Fl h 261and 262.Fl L 263primaries. 264.Pp 265These primaries can be combined with the following operators: 266.Bl -tag -width Ar 267.It Cm \&! Ar expression 268True if 269.Ar expression 270is false. 271.It Ar expression1 Fl a Ar expression2 272True if both 273.Ar expression1 274and 275.Ar expression2 276are true. 277.It Ar expression1 Fl o Ar expression2 278True if either 279.Ar expression1 280or 281.Ar expression2 282are true. 283.It Cm \&( Ns Ar expression Ns Cm \&) 284True if expression is true. 285.El 286.Pp 287The 288.Fl a 289operator has higher precedence than the 290.Fl o 291operator. 292.Pp 293Some shells may provide a builtin 294.Nm 295command which is similar or identical to this utility. 296Consult the 297.Xr builtin 1 298manual page. 299.Sh GRAMMAR AMBIGUITY 300The 301.Nm 302grammar is inherently ambiguous. 303In order to assure a degree of consistency, 304the cases described in the 305.St -p1003.2 , 306section D11.2/4.62.4, standard 307are evaluated consistently according to the rules specified in the 308standards document. 309All other cases are subject to the ambiguity in the 310command semantics. 311.Sh RETURN VALUES 312The 313.Nm 314utility exits with one of the following values: 315.Bl -tag -width Ds 316.It 0 317expression evaluated to true. 318.It 1 319expression evaluated to false or expression was 320missing. 321.It >1 322An error occurred. 323.El 324.Sh SEE ALSO 325.Xr builtin 1 , 326.Xr expr 1 , 327.Xr sh 1 , 328.Xr symlink 7 329.Sh STANDARDS 330The 331.Nm 332utility implements a superset of the 333.St -p1003.2 334specification. 335