1.\" $NetBSD: test.1,v 1.23 2007/05/15 22:00:51 uwe 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 May 31, 1993 36.Dt TEST 1 37.Os 38.Sh NAME 39.Nm test , 40.Nm \&[ 41.Nd condition evaluation utility 42.Sh SYNOPSIS 43.Nm test 44.Ar expression 45.Nm \&[ 46.Ar expression Cm ] 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 h Ar file 90True if 91.Ar file 92exists and is a symbolic link. 93.It Fl k Ar file 94True if 95.Ar file 96exists and its sticky bit is set. 97.It Fl n Ar string 98True if the length of 99.Ar string 100is nonzero. 101.It Fl p Ar file 102True if 103.Ar file 104exists and is a named pipe 105.Po Tn FIFO Pc . 106.It Fl r Ar file 107True if 108.Ar file 109exists and is readable. 110.It Fl s Ar file 111True if 112.Ar file 113exists and has a size greater 114than zero. 115.It Fl t Ar file_descriptor 116True if the file whose file descriptor number 117is 118.Ar file_descriptor 119is open and is associated with a terminal. 120.It Fl u Ar file 121True if 122.Ar file 123exists and its set user ID flag 124is set. 125.It Fl w Ar file 126True if 127.Ar file 128exists and is writable. 129True 130indicates only that the write flag is on. 131The file is not writable on a read-only file 132system even if this test indicates true. 133.It Fl x Ar file 134True if 135.Ar file 136exists and is executable. 137True 138indicates only that the execute flag is on. 139If 140.Ar file 141is a directory, true indicates that 142.Ar file 143can be searched. 144.It Fl z Ar string 145True if the length of 146.Ar string 147is zero. 148.It Fl L Ar file 149True if 150.Ar file 151exists and is a symbolic link. 152This operator is retained for compatibility with previous versions of 153this program. 154Do not rely on its existence; use 155.Fl h 156instead. 157.It Fl O Ar file 158True if 159.Ar file 160exists and its owner matches the effective user id of this process. 161.It Fl G Ar file 162True if 163.Ar file 164exists and its group matches the effective group id of this process. 165.It Fl S Ar file 166True if 167.Ar file 168exists and is a socket. 169.It Ar file1 Fl nt Ar file2 170True if 171.Ar file1 172exists and is newer than 173.Ar file2 . 174.It Ar file1 Fl ot Ar file2 175True if 176.Ar file1 177exists and is older than 178.Ar file2 . 179.It Ar file1 Fl ef Ar file2 180True if 181.Ar file1 182and 183.Ar file2 184exist and refer to the same file. 185.It Ar string 186True if 187.Ar string 188is not the null 189string. 190.It Ar \&s\&1 Cm \&= Ar \&s\&2 191True if the strings 192.Ar \&s\&1 193and 194.Ar \&s\&2 195are identical. 196.It Ar \&s\&1 Cm \&!= Ar \&s\&2 197True if the strings 198.Ar \&s\&1 199and 200.Ar \&s\&2 201are not identical. 202.It Ar \&s\&1 Cm \&\*[Lt] Ar \&s\&2 203True if string 204.Ar \&s\&1 205comes before 206.Ar \&s\&2 207based on the ASCII value of their characters. 208.It Ar \&s\&1 Cm \&\*[Gt] Ar \&s\&2 209True if string 210.Ar \&s\&1 211comes after 212.Ar \&s\&2 213based on the ASCII value of their characters. 214.It Ar \&n\&1 Fl \&eq Ar \&n\&2 215True if the integers 216.Ar \&n\&1 217and 218.Ar \&n\&2 219are algebraically 220equal. 221.It Ar \&n\&1 Fl \&ne Ar \&n\&2 222True if the integers 223.Ar \&n\&1 224and 225.Ar \&n\&2 226are not 227algebraically equal. 228.It Ar \&n\&1 Fl \> Ar \&n\&2 229True if the integer 230.Ar \&n\&1 231is algebraically 232greater than the integer 233.Ar \&n\&2 . 234.It Ar \&n\&1 Fl \&ge Ar \&n\&2 235True if the integer 236.Ar \&n\&1 237is algebraically 238greater than or equal to the integer 239.Ar \&n\&2 . 240.It Ar \&n\&1 Fl \< Ar \&n\&2 241True if the integer 242.Ar \&n\&1 243is algebraically less 244than the integer 245.Ar \&n\&2 . 246.It Ar \&n\&1 Fl \&le Ar \&n\&2 247True if the integer 248.Ar \&n\&1 249is algebraically less 250than or equal to the integer 251.Ar \&n\&2 . 252.El 253.Pp 254These primaries can be combined with the following operators: 255.Bl -tag -width Ar 256.It Cm \&! Ar expression 257True if 258.Ar expression 259is false. 260.It Ar expression1 Fl a Ar expression2 261True if both 262.Ar expression1 263and 264.Ar expression2 265are true. 266.It Ar expression1 Fl o Ar expression2 267True if either 268.Ar expression1 269or 270.Ar expression2 271are true. 272.It Cm \&( Ns Ar expression Ns Cm \&) 273True if expression is true. 274.El 275.Pp 276The 277.Fl a 278operator has higher precedence than the 279.Fl o 280operator. 281.Sh GRAMMAR AMBIGUITY 282The 283.Nm test 284grammar is inherently ambiguous. 285In order to assure a degree of consistency, the cases described in 286.St -p1003.2 287section 4.62.4, 288are evaluated consistently according to the rules specified in the 289standards document. 290All other cases are subject to the ambiguity in the command semantics. 291.Sh EXIT STATUS 292The 293.Nm test 294utility exits with one of the following values: 295.Bl -tag -width Ds 296.It 0 297expression evaluated to true. 298.It 1 299expression evaluated to false or expression was 300missing. 301.It \*[Gt]1 302An error occurred. 303.El 304.Sh STANDARDS 305The 306.Nm test 307utility implements a superset of the 308.St -p1003.2 309specification. 310