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.6 (Berkeley) 06/08/92 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 e Ar file 50True if 51.Ar file 52exists (regardless of type). 53.It Fl f Ar file 54True if 55.Ar file 56exists and is a regular file. 57.It Fl g Ar file 58True if 59.Ar file 60exists and its set group ID flag 61is set. 62.It Fl n Ar string 63True if the length of 64.Ar string 65is nonzero. 66.It Fl p Ar file 67True if 68.Ar file 69is a named pipe 70.Po Tn FIFO Pc . 71.It Fl r Ar file 72True if 73.Ar file exists and is readable. 74.It Fl s Ar file 75True if 76.Ar file 77exists and has a size greater 78than zero. 79.It Fl t Ar [file_descriptor] 80True if the file whose file descriptor number 81is 82.Ar file_descriptor 83(default 1) is open and is 84associated with a terminal. 85.It Fl u Ar file 86True if 87.Ar file 88exists and its set user ID flag 89is set. 90.It Fl w Ar file 91True if 92.Ar file 93exists and is writable. 94True 95indicates only that the write flag is on. 96The file is not writable on a read-only file 97system even if this test indicates true. 98.It Fl x Ar file 99True if 100.Ar file 101exists and is executable. 102True 103indicates only that the execute flag is on. 104If 105.Ar file 106is a directory, true indicates that 107.Ar file 108can be searched. 109.It Fl z Ar string 110True if the length of 111.Ar string 112is zero. 113.It Ar string 114True if 115.Ar string 116is not the null 117string. 118.It Ar \&s\&1 Cm \&= Ar \&s\&2 119True if the strings 120.Ar \&s\&1 121and 122.Ar \&s\&2 123are identical. 124.It Ar \&s\&1 Cm \&!= Ar \&s\&2 125True if the strings 126.Ar \&s\&1 127and 128.Ar \&s\&2 129are not identical. 130.It Ar \&n\&1 Fl \&eq Ar \&n\&2 131True if the integers 132.Ar \&n\&1 133and 134.Ar \&n\&2 135are algebraically 136equal. 137.It Ar \&n\&1 Fl \&ne Ar \&n\&2 138True if the integers 139.Ar \&n\&1 140and 141.Ar \&n\&2 142are not 143algebraically equal. 144.It Ar \&n\&1 Fl \> Ar \&n\&2 145True if the integer 146.Ar \&n\&1 147is algebraically 148greater than the integer 149.Ar \&n\&2 . 150.It Ar \&n\&1 Fl \&ge Ar \&n\&2 151True if the integer 152.Ar \&n\&1 153is algebraically 154greater than or equal to the integer 155.Ar \&n\&2 . 156.It Ar \&n\&1 Fl \< Ar \&n\&2 157True if the integer 158.Ar \&n\&1 159is algebraically less 160than the integer 161.Ar \&n\&2 . 162.It Ar \&n\&1 Fl \&le Ar \&n\&2 163True if the integer 164.Ar \&n\&1 165is algebraically less 166than or equal to the integer 167.Ar \&n\&2 . 168.El 169.Pp 170These primaries can be combined with the following operators: 171.Bl -tag -width Ar 172.It Cm \&! Ar expression 173True if 174.Ar expression 175is false. 176.It Ar expression1 Fl a Ar expression2 177True if both 178.Ar expression1 179and 180.Ar expression2 181are true. 182.It Ar expression1 Fl o Ar expression2 183True if either 184.Ar expression1 185or 186.Ar expression2 187are true. 188.It Cm \&( Ns Ar expression Ns Cm \&) 189True if expression is true. 190.El 191.Pp 192The 193.Fl a 194operator has higher precedence than the 195.Fl o 196operator. 197.Sh GRAMMAR AMBIGUITY 198The 199.Nm test 200grammar is inherently ambiguous. In order to assure a degree of consistency, 201the cases described in the 202.St -p1003.2 , 203section D11.2/4.62.4, standard 204are evaluated consistently according to the rules specified in the 205standards document. All other cases are subject to the ambiguity in the 206command semantics. 207.Sh RETURN VALUES 208The 209.Nm test 210utility exits with one of the following values: 211.Bl -tag -width Ds 212.It 0 213expression evaluated to true. 214.It 1 215expression evaluated to false or expression was 216missing. 217.It >1 218An error occurred. 219.El 220.Sh STANDARDS 221The 222.Nm test 223function is expected to be 224.St -p1003.2 225compatible. 226