1.\" $NetBSD: test.1,v 1.30 2016/08/12 03:17:41 sevan Exp $ 2.\" 3.\" Copyright (c) 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" the Institute of Electrical and Electronics Engineers, Inc. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. Neither the name of the University nor the names of its contributors 18.\" may be used to endorse or promote products derived from this software 19.\" without specific prior written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.\" @(#)test.1 8.1 (Berkeley) 5/31/93 34.\" 35.Dd August 12, 2016 36.Dt TEST 1 37.Os 38.Sh NAME 39.Nm test , 40.Nm \&[ 41.Nd condition evaluation utility 42.Sh SYNOPSIS 43.Nm 44.Ar expression 45.Nm \&[ 46.Ar expression Cm \&] 47.Sh DESCRIPTION 48The 49.Nm 50utility evaluates 51.Ar expression 52and, if it evaluates 53to true, returns a zero (true) exit status; otherwise 54it returns 1 (false). 55If 56.Ar expression 57is not given, 58.Nm 59also 60returns 1 (false). 61.Pp 62All operators and flags are separate arguments to the 63.Nm 64utility. 65.Pp 66The following primaries are used to construct 67.Ar expression : 68.Bl -tag -width Ar 69.It Fl b Ar file 70True if 71.Ar file 72exists and is a block special 73file. 74.It Fl c Ar file 75True if 76.Ar file 77exists and is a character 78special file. 79.It Fl d Ar file 80True if 81.Ar file 82exists and is a directory. 83.It Fl e Ar file 84True if 85.Ar file 86exists (regardless of type). 87.It Fl f Ar file 88True if 89.Ar file 90exists and is a regular file. 91.It Fl g Ar file 92True if 93.Ar file 94exists and its set group ID flag 95is set. 96.It Fl h Ar file 97True if 98.Ar file 99exists and is a symbolic link. 100.It Fl k Ar file 101True if 102.Ar file 103exists and its sticky bit is set. 104.It Fl n Ar string 105True if the length of 106.Ar string 107is nonzero. 108.It Fl p Ar file 109True if 110.Ar file 111exists and is a named pipe 112.Po Tn FIFO Pc . 113.It Fl r Ar file 114True if 115.Ar file 116exists and is readable. 117.It Fl s Ar file 118True if 119.Ar file 120exists and has a size greater 121than zero. 122.It Fl t Ar file_descriptor 123True if the file whose file descriptor number 124is 125.Ar file_descriptor 126is open and is associated with a terminal. 127.It Fl u Ar file 128True if 129.Ar file 130exists and its set user ID flag 131is set. 132.It Fl w Ar file 133True if 134.Ar file 135exists and is writable. 136True 137indicates only that the write flag is on. 138The file is not writable on a read-only file 139system even if this test indicates true. 140.It Fl x Ar file 141True if 142.Ar file 143exists and is executable. 144True 145indicates only that the execute flag is on. 146If 147.Ar file 148is a directory, true indicates that 149.Ar file 150can be searched. 151.It Fl z Ar string 152True if the length of 153.Ar string 154is zero. 155.It Fl L Ar file 156True if 157.Ar file 158exists and is a symbolic link. 159This operator is retained for compatibility with previous versions of 160this program. 161Do not rely on its existence; use 162.Fl h 163instead. 164.It Fl O Ar file 165True if 166.Ar file 167exists and its owner matches the effective user id of this process. 168.It Fl G Ar file 169True if 170.Ar file 171exists and its group matches the effective group id of this process. 172.It Fl S Ar file 173True if 174.Ar file 175exists and is a socket. 176.It Ar file1 Fl nt Ar file2 177True if 178.Ar file1 179exists and is newer than 180.Ar file2 . 181.It Ar file1 Fl ot Ar file2 182True if 183.Ar file1 184exists and is older than 185.Ar file2 . 186.It Ar file1 Fl ef Ar file2 187True if 188.Ar file1 189and 190.Ar file2 191exist and refer to the same file. 192.It Ar string 193True if 194.Ar string 195is not the null 196string. 197.It Ar \&s\&1 Cm \&= Ar \&s\&2 198True if the strings 199.Ar \&s\&1 200and 201.Ar \&s\&2 202are identical. 203.It Ar \&s\&1 Cm \&!= Ar \&s\&2 204True if the strings 205.Ar \&s\&1 206and 207.Ar \&s\&2 208are not identical. 209.It Ar \&s\&1 Cm \&\*[Lt] Ar \&s\&2 210True if string 211.Ar \&s\&1 212comes before 213.Ar \&s\&2 214based on the ASCII value of their characters. 215.It Ar \&s\&1 Cm \&\*[Gt] Ar \&s\&2 216True if string 217.Ar \&s\&1 218comes after 219.Ar \&s\&2 220based on the ASCII value of their characters. 221.It Ar \&n\&1 Fl \&eq Ar \&n\&2 222True if the integers 223.Ar \&n\&1 224and 225.Ar \&n\&2 226are algebraically 227equal. 228.It Ar \&n\&1 Fl \&ne Ar \&n\&2 229True if the integers 230.Ar \&n\&1 231and 232.Ar \&n\&2 233are not 234algebraically equal. 235.It Ar \&n\&1 Fl \> Ar \&n\&2 236True if the integer 237.Ar \&n\&1 238is algebraically 239greater than the integer 240.Ar \&n\&2 . 241.It Ar \&n\&1 Fl \&ge Ar \&n\&2 242True if the integer 243.Ar \&n\&1 244is algebraically 245greater than or equal to the integer 246.Ar \&n\&2 . 247.It Ar \&n\&1 Fl \< Ar \&n\&2 248True if the integer 249.Ar \&n\&1 250is algebraically less 251than the integer 252.Ar \&n\&2 . 253.It Ar \&n\&1 Fl \&le Ar \&n\&2 254True if the integer 255.Ar \&n\&1 256is algebraically less 257than or equal to the integer 258.Ar \&n\&2 . 259.El 260.Pp 261These primaries can be combined with the following operators: 262.Bl -tag -width Ar 263.It Cm \&! Ar expression 264True if 265.Ar expression 266is false. 267.It Ar expression1 Fl a Ar expression2 268True if both 269.Ar expression1 270and 271.Ar expression2 272are true. 273.It Ar expression1 Fl o Ar expression2 274True if either 275.Ar expression1 276or 277.Ar expression2 278is true. 279.It Cm \&( Ar expression Cm \&) 280True if 281.Ar expression 282is true. 283.El 284.Pp 285The 286.Fl a 287operator has higher precedence than the 288.Fl o 289operator. 290.Pp 291Note that all file tests with the exception of 292.Fl h 293and 294.Fl L 295follow symbolic links and thus evaluate the test for the file pointed at. 296.Sh EXIT STATUS 297The 298.Nm 299utility exits with one of the following values: 300.Bl -tag -width Ds 301.It 0 302.Ar expression 303evaluated to true. 304.It 1 305.Ar expression 306evaluated to false or was missing. 307.It \*[Gt]1 308An error occurred. 309.El 310.Sh STANDARDS 311The 312.Nm 313utility implements a superset of the 314.St -p1003.2 315specification. 316.Sh HISTORY 317A 318.Nm 319utility appeared in 320.At v7 . 321.Sh CAVEATS 322The 323.Nm 324grammar is inherently ambiguous. 325In order to assure a degree of consistency, the cases described in 326.St -p1003.2 327section 4.62.4, 328are evaluated consistently according to the rules specified in the 329standards document. 330All other cases are subject to the ambiguity in the command semantics. 331