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.7 2007/10/20 17:56:46 swildner 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, 58.Nm 59also returns 1 (false). 60.Pp 61All operators and flags are separate arguments to the 62.Nm 63utility. 64.Pp 65The following primaries are used to construct expression: 66.Bl -tag -width Ar 67.It Fl b Ar file 68True if 69.Ar file 70exists and is a block special 71file. 72.It Fl c Ar file 73True if 74.Ar file 75exists and is a character 76special file. 77.It Fl d Ar file 78True if 79.Ar file 80exists and is a directory. 81.It Fl e Ar file 82True if 83.Ar file 84exists (regardless of type). 85.It Fl f Ar file 86True if 87.Ar file 88exists and is a regular file. 89.It Fl g Ar file 90True if 91.Ar file 92exists and its set group ID flag 93is set. 94.It Fl h Ar file 95True if 96.Ar file 97exists and is a symbolic link. 98This operator is retained for compatibility with previous versions of 99this program. 100Do not rely on its existence; use 101.Fl L 102instead. 103.It Fl k Ar file 104True if 105.Ar file 106exists and its sticky bit is set. 107.It Fl n Ar string 108True if the length of 109.Ar string 110is nonzero. 111.It Fl p Ar file 112True if 113.Ar file 114is a named pipe 115.Pq Tn FIFO . 116.It Fl r Ar file 117True if 118.Ar file 119exists and is readable. 120.It Fl s Ar file 121True if 122.Ar file 123exists and has a size greater 124than zero. 125.It Fl t Ar file_descriptor 126True if the file whose file descriptor number 127is 128.Ar file_descriptor 129is open and is associated with a terminal. 130.It Fl u Ar file 131True if 132.Ar file 133exists and its set user ID flag 134is set. 135.It Fl w Ar file 136True if 137.Ar file 138exists and is writable. 139True 140indicates both that the write flag is on and that 141.Ar file 142resides on a read-write file system. 143.Pp 144Note that this behaviour is specific to 145.Dx . 146When writing portable scripts, keep in mind that 147on some systems, this test may 148indicate only that the write flag is on. 149.It Fl x Ar file 150True if 151.Ar file 152exists and is executable. 153True 154indicates only that the execute flag is on. 155If 156.Ar file 157is a directory, true indicates that 158.Ar file 159can be searched. 160.It Fl z Ar string 161True if the length of 162.Ar string 163is zero. 164.It Fl L Ar file 165True if 166.Ar file 167exists and is a symbolic link. 168.It Fl O Ar file 169True if 170.Ar file 171exists and its owner matches the effective user id of this process. 172.It Fl G Ar file 173True if 174.Ar file 175exists and its group matches the effective group id of this process. 176.It Fl S Ar file 177True if 178.Ar file 179exists and is a socket. 180.It Ar file1 Fl nt Ar file2 181True if 182.Ar file1 183exists and is newer than 184.Ar file2 . 185.It Ar file1 Fl ot Ar file2 186True if 187.Ar file1 188exists and is older than 189.Ar file2 . 190.It Ar file1 Fl ef Ar file2 191True if 192.Ar file1 193and 194.Ar file2 195exist and refer to the same file. 196.It Ar string 197True if 198.Ar string 199is not the null 200string. 201.It Ar \&s\&1 Cm \&= Ar \&s\&2 202True if the strings 203.Ar \&s\&1 204and 205.Ar \&s\&2 206are identical. 207.It Ar \&s\&1 Cm \&!= Ar \&s\&2 208True if the strings 209.Ar \&s\&1 210and 211.Ar \&s\&2 212are not identical. 213.It Ar \&s\&1 Cm \&< Ar \&s\&2 214True if string 215.Ar \&s\&1 216comes before 217.Ar \&s\&2 218based on the ASCII value of their characters. 219.It Ar \&s\&1 Cm \&> Ar \&s\&2 220True if string 221.Ar \&s\&1 222comes after 223.Ar \&s\&2 224based on the ASCII value of their characters. 225.It Ar \&s\&1 226True if 227.Ar \&s\&1 228is not the null 229string. 230.It Ar \&n\&1 Fl \&eq Ar \&n\&2 231True if the integers 232.Ar \&n\&1 233and 234.Ar \&n\&2 235are algebraically 236equal. 237.It Ar \&n\&1 Fl \&ne Ar \&n\&2 238True if the integers 239.Ar \&n\&1 240and 241.Ar \&n\&2 242are not 243algebraically equal. 244.It Ar \&n\&1 Fl \> Ar \&n\&2 245True if the integer 246.Ar \&n\&1 247is algebraically 248greater than the integer 249.Ar \&n\&2 . 250.It Ar \&n\&1 Fl \&ge Ar \&n\&2 251True if the integer 252.Ar \&n\&1 253is algebraically 254greater than or equal to the integer 255.Ar \&n\&2 . 256.It Ar \&n\&1 Fl \< Ar \&n\&2 257True if the integer 258.Ar \&n\&1 259is algebraically less 260than the integer 261.Ar \&n\&2 . 262.It Ar \&n\&1 Fl \&le Ar \&n\&2 263True if the integer 264.Ar \&n\&1 265is algebraically less 266than or equal to the integer 267.Ar \&n\&2 . 268.El 269.Pp 270These primaries can be combined with the following operators: 271.Bl -tag -width Ar 272.It Cm \&! Ar expression 273True if 274.Ar expression 275is false. 276.It Ar expression1 Fl a Ar expression2 277True if both 278.Ar expression1 279and 280.Ar expression2 281are true. 282.It Ar expression1 Fl o Ar expression2 283True if either 284.Ar expression1 285or 286.Ar expression2 287are true. 288.It Cm \&( Ns Ar expression Ns Cm \&) 289True if expression is true. 290.El 291.Pp 292The 293.Fl a 294operator has higher precedence than the 295.Fl o 296operator. 297.Pp 298Some shells may provide a builtin 299.Nm 300command which is similar or identical to this utility. 301Consult the 302.Xr builtin 1 303manual page. 304.Sh GRAMMAR AMBIGUITY 305The 306.Nm 307grammar is inherently ambiguous. In order to assure a degree of consistency, 308the cases described in the 309.St -p1003.2 , 310section D11.2/4.62.4, standard 311are evaluated consistently according to the rules specified in the 312standards document. All other cases are subject to the ambiguity in the 313command semantics. 314.Sh DIAGNOSTICS 315The 316.Nm 317utility exits with one of the following values: 318.Bl -tag -width Ds 319.It 0 320expression evaluated to true. 321.It 1 322expression evaluated to false or expression was 323missing. 324.It >1 325An error occurred. 326.El 327.Sh SEE ALSO 328.Xr builtin 1 , 329.Xr expr 1 , 330.Xr sh 1 331.Sh STANDARDS 332The 333.Nm 334utility implements a superset of the 335.St -p1003.2 336specification. 337