1*1245b84dSschwarze.\" $OpenBSD: test.1,v 1.35 2024/06/18 16:41:39 schwarze Exp $ 2df930be7Sderaadt.\" $NetBSD: test.1,v 1.6 1995/03/21 07:04:03 cgd Exp $ 3df930be7Sderaadt.\" 4df930be7Sderaadt.\" Copyright (c) 1991, 1993 5df930be7Sderaadt.\" The Regents of the University of California. All rights reserved. 6df930be7Sderaadt.\" 7df930be7Sderaadt.\" This code is derived from software contributed to Berkeley by 8df930be7Sderaadt.\" the Institute of Electrical and Electronics Engineers, Inc. 9df930be7Sderaadt.\" 10df930be7Sderaadt.\" Redistribution and use in source and binary forms, with or without 11df930be7Sderaadt.\" modification, are permitted provided that the following conditions 12df930be7Sderaadt.\" are met: 13df930be7Sderaadt.\" 1. Redistributions of source code must retain the above copyright 14df930be7Sderaadt.\" notice, this list of conditions and the following disclaimer. 15df930be7Sderaadt.\" 2. Redistributions in binary form must reproduce the above copyright 16df930be7Sderaadt.\" notice, this list of conditions and the following disclaimer in the 17df930be7Sderaadt.\" documentation and/or other materials provided with the distribution. 1829295d1cSmillert.\" 3. Neither the name of the University nor the names of its contributors 19df930be7Sderaadt.\" may be used to endorse or promote products derived from this software 20df930be7Sderaadt.\" without specific prior written permission. 21df930be7Sderaadt.\" 22df930be7Sderaadt.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23df930be7Sderaadt.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24df930be7Sderaadt.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25df930be7Sderaadt.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26df930be7Sderaadt.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27df930be7Sderaadt.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28df930be7Sderaadt.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29df930be7Sderaadt.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30df930be7Sderaadt.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31df930be7Sderaadt.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32df930be7Sderaadt.\" SUCH DAMAGE. 33df930be7Sderaadt.\" 34df930be7Sderaadt.\" @(#)test.1 8.1 (Berkeley) 5/31/93 35df930be7Sderaadt.\" 36*1245b84dSschwarze.Dd $Mdocdate: June 18 2024 $ 37df930be7Sderaadt.Dt TEST 1 38df930be7Sderaadt.Os 39df930be7Sderaadt.Sh NAME 40d77b5180Sjmc.Nm test , 41d77b5180Sjmc.Nm \&[ 42887b99f6Saaron.Nd condition evaluation utility 43df930be7Sderaadt.Sh SYNOPSIS 44df930be7Sderaadt.Nm test 45df930be7Sderaadt.Ar expression 468025da82Sjmc.Nm \&[ 478025da82Sjmc.Ar expression Nm \&] 48df930be7Sderaadt.Sh DESCRIPTION 49df930be7SderaadtThe 50f11c8a18Saaron.Nm 51887b99f6Saaronutility evaluates the 52887b99f6Saaron.Ar expression 53887b99f6Saaronand, if it evaluates 54df930be7Sderaadtto true, returns a zero (true) exit status; otherwise 55df930be7Sderaadtit returns 1 (false). 56887b99f6SaaronIf no 57887b99f6Saaron.Ar expression 58887b99f6Saaronis given, 59f81d96dfSaaron.Nm 60f81d96dfSaaronalso 61df930be7Sderaadtreturns 1 (false). 62d77b5180SjmcThe form 63d77b5180Sjmc.Nm \&[ 64d77b5180Sjmcis an alias for 65d77b5180Sjmc.Nm test . 66df930be7Sderaadt.Pp 67df930be7SderaadtAll operators and flags are separate arguments to the 68f11c8a18Saaron.Nm 69df930be7Sderaadtutility. 70b34770f9SjmcSymbolic links are followed for all primaries except 71b34770f9Sjmc.Fl h 72b34770f9Sjmcand 73b34770f9Sjmc.Fl L . 74df930be7Sderaadt.Pp 75887b99f6SaaronThe following primaries are used to construct 76887b99f6Saaron.Ar expression : 77b34770f9Sjmc.Bl -tag -width Ds 78df930be7Sderaadt.It Fl b Ar file 79df930be7SderaadtTrue if 80df930be7Sderaadt.Ar file 81df930be7Sderaadtexists and is a block special 82df930be7Sderaadtfile. 83df930be7Sderaadt.It Fl c Ar file 84df930be7SderaadtTrue if 85df930be7Sderaadt.Ar file 86df930be7Sderaadtexists and is a character 87df930be7Sderaadtspecial file. 88df930be7Sderaadt.It Fl d Ar file 89df930be7SderaadtTrue if 90df930be7Sderaadt.Ar file 91df930be7Sderaadtexists and is a directory. 92df930be7Sderaadt.It Fl e Ar file 93df930be7SderaadtTrue if 94df930be7Sderaadt.Ar file 95df930be7Sderaadtexists (regardless of type). 96df930be7Sderaadt.It Fl f Ar file 97df930be7SderaadtTrue if 98df930be7Sderaadt.Ar file 99df930be7Sderaadtexists and is a regular file. 1002bdd6c0aSjmc.It Fl G Ar file 1012bdd6c0aSjmcTrue if 1022bdd6c0aSjmc.Ar file 1032bdd6c0aSjmcexists and its group matches the effective group ID of this process. 104df930be7Sderaadt.It Fl g Ar file 105df930be7SderaadtTrue if 106df930be7Sderaadt.Ar file 107f81d96dfSaaronexists and its set-group-ID flag 108df930be7Sderaadtis set. 109dd8ee1deSderaadt.It Fl h Ar file 110dd8ee1deSderaadtTrue if 111dd8ee1deSderaadt.Ar file 112dd8ee1deSderaadtexists and is a symbolic link. 113*1245b84dSschwarzeIdentical to 114*1245b84dSschwarze.Fl L . 115df930be7Sderaadt.It Fl k Ar file 116df930be7SderaadtTrue if 117df930be7Sderaadt.Ar file 118df930be7Sderaadtexists and its sticky bit is set. 1192bdd6c0aSjmc.It Fl L Ar file 1202bdd6c0aSjmcTrue if 1212bdd6c0aSjmc.Ar file 1222bdd6c0aSjmcexists and is a symbolic link. 123*1245b84dSschwarzeIdentical to 124*1245b84dSschwarze.Fl h . 125df930be7Sderaadt.It Fl n Ar string 126df930be7SderaadtTrue if the length of 127df930be7Sderaadt.Ar string 128df930be7Sderaadtis nonzero. 1292bdd6c0aSjmc.It Fl O Ar file 1302bdd6c0aSjmcTrue if 1312bdd6c0aSjmc.Ar file 1322bdd6c0aSjmcexists and its owner matches the effective user ID of this process. 133df930be7Sderaadt.It Fl p Ar file 134df930be7SderaadtTrue if 135df930be7Sderaadt.Ar file 136df930be7Sderaadtis a named pipe 137afee87bcSjmc.Pq Tn FIFO . 138df930be7Sderaadt.It Fl r Ar file 139df930be7SderaadtTrue if 140df930be7Sderaadt.Ar file 141df930be7Sderaadtexists and is readable. 1422bdd6c0aSjmc.It Fl S Ar file 1432bdd6c0aSjmcTrue if 1442bdd6c0aSjmc.Ar file 1452bdd6c0aSjmcexists and is a socket. 146df930be7Sderaadt.It Fl s Ar file 147df930be7SderaadtTrue if 148df930be7Sderaadt.Ar file 149df930be7Sderaadtexists and has a size greater 150df930be7Sderaadtthan zero. 151df930be7Sderaadt.It Fl t Ar file_descriptor 152df930be7SderaadtTrue if the file whose file descriptor number 153df930be7Sderaadtis 154df930be7Sderaadt.Ar file_descriptor 155ef9fc2e5Sopis open and is associated with a terminal. 156df930be7Sderaadt.It Fl u Ar file 157df930be7SderaadtTrue if 158df930be7Sderaadt.Ar file 159f81d96dfSaaronexists and its set-user-ID flag 160df930be7Sderaadtis set. 161df930be7Sderaadt.It Fl w Ar file 162df930be7SderaadtTrue if 163df930be7Sderaadt.Ar file 164df930be7Sderaadtexists and is writable. 165df930be7SderaadtTrue 166df930be7Sderaadtindicates only that the write flag is on. 167df930be7SderaadtThe file is not writable on a read-only file 168df930be7Sderaadtsystem even if this test indicates true. 169df930be7Sderaadt.It Fl x Ar file 170df930be7SderaadtTrue if 171df930be7Sderaadt.Ar file 172df930be7Sderaadtexists and is executable. 173df930be7SderaadtTrue 174df930be7Sderaadtindicates only that the execute flag is on. 175df930be7SderaadtIf 176df930be7Sderaadt.Ar file 177df930be7Sderaadtis a directory, true indicates that 178df930be7Sderaadt.Ar file 179df930be7Sderaadtcan be searched. 180df930be7Sderaadt.It Fl z Ar string 181df930be7SderaadtTrue if the length of 182df930be7Sderaadt.Ar string 183df930be7Sderaadtis zero. 184df930be7Sderaadt.It Ar file1 Fl nt Ar file2 185df930be7SderaadtTrue if 186df930be7Sderaadt.Ar file1 187df930be7Sderaadtexists and is newer than 188df930be7Sderaadt.Ar file2 . 189df930be7Sderaadt.It Ar file1 Fl ot Ar file2 190df930be7SderaadtTrue if 191df930be7Sderaadt.Ar file1 192df930be7Sderaadtexists and is older than 193df930be7Sderaadt.Ar file2 . 194df930be7Sderaadt.It Ar file1 Fl ef Ar file2 195df930be7SderaadtTrue if 196df930be7Sderaadt.Ar file1 197df930be7Sderaadtand 198df930be7Sderaadt.Ar file2 199df930be7Sderaadtexist and refer to the same file. 2006db4d1fcSjmc.It Ar s1 Cm = Ar s2 201df930be7SderaadtTrue if the strings 2026db4d1fcSjmc.Ar s1 203df930be7Sderaadtand 2046db4d1fcSjmc.Ar s2 205df930be7Sderaadtare identical. 2066db4d1fcSjmc.It Ar s1 Cm != Ar s2 207df930be7SderaadtTrue if the strings 2086db4d1fcSjmc.Ar s1 209df930be7Sderaadtand 2106db4d1fcSjmc.Ar s2 211df930be7Sderaadtare not identical. 2126db4d1fcSjmc.It Ar s1 Cm \*(Lt Ar s2 213df930be7SderaadtTrue if string 2146db4d1fcSjmc.Ar s1 215df930be7Sderaadtcomes before 2166db4d1fcSjmc.Ar s2 217df930be7Sderaadtbased on the ASCII value of their characters. 2186db4d1fcSjmc.It Ar s1 Cm \*(Gt Ar s2 219df930be7SderaadtTrue if string 2206db4d1fcSjmc.Ar s1 221df930be7Sderaadtcomes after 2226db4d1fcSjmc.Ar s2 223df930be7Sderaadtbased on the ASCII value of their characters. 2246db4d1fcSjmc.It Ar s1 225df930be7SderaadtTrue if 2266db4d1fcSjmc.Ar s1 227df930be7Sderaadtis not the null 228df930be7Sderaadtstring. 2296db4d1fcSjmc.It Ar n1 Fl eq Ar n2 230df930be7SderaadtTrue if the integers 2316db4d1fcSjmc.Ar n1 232df930be7Sderaadtand 2336db4d1fcSjmc.Ar n2 234df930be7Sderaadtare algebraically 235df930be7Sderaadtequal. 2366db4d1fcSjmc.It Ar n1 Fl ne Ar n2 237df930be7SderaadtTrue if the integers 2386db4d1fcSjmc.Ar n1 239df930be7Sderaadtand 2406db4d1fcSjmc.Ar n2 241df930be7Sderaadtare not 242df930be7Sderaadtalgebraically equal. 2436db4d1fcSjmc.It Ar n1 Fl gt Ar n2 244df930be7SderaadtTrue if the integer 2456db4d1fcSjmc.Ar n1 246df930be7Sderaadtis algebraically 247df930be7Sderaadtgreater than the integer 2486db4d1fcSjmc.Ar n2 . 2496db4d1fcSjmc.It Ar n1 Fl ge Ar n2 250df930be7SderaadtTrue if the integer 2516db4d1fcSjmc.Ar n1 252df930be7Sderaadtis algebraically 253df930be7Sderaadtgreater than or equal to the integer 2546db4d1fcSjmc.Ar n2 . 2556db4d1fcSjmc.It Ar n1 Fl \< Ar n2 256df930be7SderaadtTrue if the integer 2576db4d1fcSjmc.Ar n1 258df930be7Sderaadtis algebraically less 259df930be7Sderaadtthan the integer 2606db4d1fcSjmc.Ar n2 . 2616db4d1fcSjmc.It Ar n1 Fl le Ar n2 262df930be7SderaadtTrue if the integer 2636db4d1fcSjmc.Ar n1 264df930be7Sderaadtis algebraically less 265df930be7Sderaadtthan or equal to the integer 2666db4d1fcSjmc.Ar n2 . 267df930be7Sderaadt.El 268df930be7Sderaadt.Pp 269b34770f9SjmcThese primaries can be combined with the following operators. 270b34770f9SjmcThe 271b34770f9Sjmc.Fl a 272b34770f9Sjmcoperator has higher precedence than the 273b34770f9Sjmc.Fl o 274b34770f9Sjmcoperator. 275b34770f9Sjmc.Bl -tag -width Ds 276df930be7Sderaadt.It Cm \&! Ar expression 277df930be7SderaadtTrue if 278df930be7Sderaadt.Ar expression 279df930be7Sderaadtis false. 280df930be7Sderaadt.It Ar expression1 Fl a Ar expression2 281df930be7SderaadtTrue if both 282df930be7Sderaadt.Ar expression1 283df930be7Sderaadtand 284df930be7Sderaadt.Ar expression2 285df930be7Sderaadtare true. 286df930be7Sderaadt.It Ar expression1 Fl o Ar expression2 287df930be7SderaadtTrue if either 288df930be7Sderaadt.Ar expression1 289df930be7Sderaadtor 290df930be7Sderaadt.Ar expression2 291df930be7Sderaadtare true. 292fdcc147aSjmc.It Cm \&( Ar expression Cm \&) 293887b99f6SaaronTrue if 294887b99f6Saaron.Ar expression 295887b99f6Saaronis true. 296df930be7Sderaadt.El 29759a5f2b9Sjmc.Sh EXIT STATUS 298f7cb3118SjmcThe 299f7cb3118Sjmc.Nm 300f7cb3118Sjmcutility exits with one of the following values: 301f7cb3118Sjmc.Pp 30259a5f2b9Sjmc.Bl -tag -width Ds -offset indent -compact 303f7cb3118Sjmc.It 0 304f7cb3118SjmcExpression evaluated to true. 305f7cb3118Sjmc.It 1 306f7cb3118SjmcExpression evaluated to false or expression was 307f7cb3118Sjmcmissing. 308f7cb3118Sjmc.It \*(Gt1 309f7cb3118SjmcAn error occurred. 310f7cb3118Sjmc.El 311df930be7Sderaadt.Sh GRAMMAR AMBIGUITY 312df930be7SderaadtThe 313f11c8a18Saaron.Nm 3148c926583Saarongrammar is inherently ambiguous. 3158c926583SaaronIn order to assure a degree of consistency, 316df930be7Sderaadtthe cases described in 317df930be7Sderaadt.St -p1003.2 318f81d96dfSaaronsection D11.2/4.62.4 319df930be7Sderaadtare evaluated consistently according to the rules specified in the 3208c926583Saaronstandards document. 3218c926583SaaronAll other cases are subject to the ambiguity in the 322df930be7Sderaadtcommand semantics. 323ab7e6c46Sjmc.Sh SEE ALSO 324ab7e6c46Sjmc.Xr ksh 1 325df930be7Sderaadt.Sh STANDARDS 326df930be7SderaadtThe 327f11c8a18Saaron.Nm 3280f3f4dbcSjmcutility is compliant with the 32999332e38Sjmc.St -p1003.1-2008 330df930be7Sderaadtspecification. 3310f3f4dbcSjmc.Pp 3320f3f4dbcSjmcThe primaries 3330f3f4dbcSjmc.Fl G , 3340f3f4dbcSjmc.Fl k , 3350f3f4dbcSjmc.Fl O , 3360f3f4dbcSjmc.Fl nt , 3370f3f4dbcSjmc.Fl ot , 3380f3f4dbcSjmc.Fl ef , 3390f3f4dbcSjmc.Cm \*(Lt , 3400f3f4dbcSjmcand 3410f3f4dbcSjmc.Cm \*(Gt 3420f3f4dbcSjmcare extensions to that specification. 343d406b0bbSjmc.Pp 344b1342409SjmcThe operators 345b1342409Sjmc.Fl a , 346b1342409Sjmc.Fl o , 347b1342409Sjmcand 348b1342409Sjmc.Cm () 349b1342409Sjmcare marked by 350b1342409Sjmc.St -p1003.1-2008 351b1342409Sjmcas part of X/Open System Interfaces and obsolete. 352b1342409Sjmc.Pp 353d406b0bbSjmc.Nm 354d406b0bbSjmcalso exists as a built-in to 355d406b0bbSjmc.Xr ksh 1 , 356d406b0bbSjmcthough with a different syntax. 357b35d111eSschwarze.Sh HISTORY 358b35d111eSschwarzeA 359b35d111eSschwarze.Nm 360b35d111eSschwarzeutility appeared in 361b35d111eSschwarze.At v7 . 362