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