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