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