1.\" Copyright (c) 1991 Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.roff% 5.\" 6.\" @(#)test.1 6.3 (Berkeley) 04/22/91 7.\" 8.Dd 9.Dt TEST 1 10.Os BSD 4.4 11.Sh NAME 12.Nm test 13.Nd Condition evaluation utility. 14.Sh SYNOPSIS 15.Nm test 16.Ar expression 17.Sh DESCRIPTION 18The 19.Nm test 20utility evaluates the expression and, if it evaluates 21to true, returns a zero (true) exit status; otherwise 22it returns 1 (false). 23If there is no expression, test also 24returns 1 (false). 25.Pp 26All operators and flags are separate arguments to the 27.Nm test 28utility. 29.Pp 30The following primaries are used to construct expression: 31.Bl -tag -width Ar 32.It Fl b Ar file 33True if 34.Ar file 35exists and is a block special 36file. 37.It Fl c Ar file 38True if 39.Ar file 40exists and is a character 41special file. 42.It Fl d Ar file 43True if 44.Ar file 45exists and is a directory. 46.It Fl f Ar file 47True if 48.Ar file 49exists and is a regular file. 50.It Fl g Ar file 51True if 52.Ar file 53exists and its set group ID flag 54is set. 55.It Fl n Ar string 56True if the length of 57.Ar string 58is nonzero. 59.It Fl p Ar file 60True if 61.Ar file 62is a named pipe 63.Po Tn FIFO Pc . 64.It Fl r Ar file 65True if 66.Ar file exists and is readable. 67.It Fl s Ar file 68True if 69.Ar file 70exists and has a size greater 71than zero. 72.It Fl t Ar [file_descriptor] 73True if the file whose file descriptor number 74is 75.Ar file_descriptor 76(default 1) is open and is 77associated with a terminal. 78.It Fl u Ar file 79True if 80.Ar file 81exists and its set user ID flag 82is set. 83.It Fl w Ar file 84True if 85.Ar file 86exists and is writable. 87True 88indicates only that the write flag is on. 89The file is not writable on a read-only file 90system even if this test indicates true. 91.It Fl x Ar file 92True if 93.Ar file 94exists and is executable. 95True 96indicates only that the execute flag is on. 97If 98.Ar file 99is a directory, true indicates that 100.Ar file 101can be searched. 102.It Fl z Ar string 103True if the length of 104.Ar string 105is zero. 106.It Ar string 107True if 108.Ar string 109is not the null 110string. 111.It Ar \&s\&1 Cm \&= Ar \&s\&2 112True if the strings 113.Ar \&s\&1 114and 115.Ar \&s\&2 116are identical. 117.It Ar \&s\&1 Cm \&!= Ar \&s\&2 118True if the strings 119.Ar \&s\&1 120and 121.Ar \&s\&2 122are not identical. 123.It Ar \&n\&1 Fl \&eq Ar \&n\&2 124True if the integers 125.Ar \&n\&1 126and 127.Ar \&n\&2 128are algebraically 129equal. 130.It Ar \&n\&1 Fl \&ne Ar \&n\&2 131True if the integers 132.Ar \&n\&1 133and 134.Ar \&n\&2 135are not 136algebraically equal. 137.It Ar \&n\&1 Fl \> Ar \&n\&2 138True if the integer 139.Ar \&n\&1 140is algebraically 141greater than the integer 142.Ar \&n\&2 . 143.It Ar \&n\&1 Fl \&ge Ar \&n\&2 144True if the integer 145.Ar \&n\&1 146is algebraically 147greater than or equal to the integer 148.Ar \&n\&2 . 149.It Ar \&n\&1 Fl \< Ar \&n\&2 150True if the integer 151.Ar \&n\&1 152is algebraically less 153than the integer 154.Ar \&n\&2 . 155.It Ar \&n\&1 Fl \&le Ar \&n\&2 156True if the integer 157.Ar \&n\&1 158is algebraically less 159than or equal to the integer 160.Ar \&n\&2 . 161.El 162.Pp 163These primaries can be combined with the following operators: 164.Bl -tag -width Ar 165.It Cm \&! Ar expression 166True if 167.Ar expression 168is false. 169.It Ar expression1 Fl a Ar expression2 170True if both 171.Ar expression1 172and 173.Ar expression2 174are true. 175.It Ar expression1 Fl o Ar expression2 176True if either 177.Ar expression1 178or 179.Ar expression2 180are true. 181.It Cm \&( Ns Ar expression Ns Cm \&) 182True if expression is true. 183.El 184.Pp 185The 186.Fl a 187operator has higher precedence than the 188.Fl o 189operator. 190.Pp 191The 192.Nm test 193utility exits with one of the following values: 194.Bl -tag -width Ds 195.It 0 196expression evaluated to true. 197.It 1 198expression evaluated to false or expression was 199missing. 200.It >1 201An error occurred. 202.El 203.Sh STANDARDS 204The 205.Nm test 206function is expected to be 207.Tn POSIX 2081003.2 compatible. 209