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