1*60726Sbostic.\" Copyright (c) 1991, 1993 2*60726Sbostic.\" The Regents of the University of California. All rights reserved. 319509Smckusick.\" 450211Sbostic.\" This code is derived from software contributed to Berkeley by 550211Sbostic.\" the Institute of Electrical and Electronics Engineers, Inc. 650211Sbostic.\" 748537Scael.\" %sccs.include.redist.roff% 848537Scael.\" 9*60726Sbostic.\" @(#)test.1 8.1 (Berkeley) 05/31/93 1048537Scael.\" 1148537Scael.Dd 1248537Scael.Dt TEST 1 1350790Scael.Os 1448537Scael.Sh NAME 1548537Scael.Nm test 1648537Scael.Nd condition evaluation utility 1748537Scael.Sh SYNOPSIS 1848537Scael.Nm test 1948537Scael.Ar expression 2048537Scael.Sh DESCRIPTION 2148537ScaelThe 2248537Scael.Nm test 2348537Scaelutility evaluates the expression and, if it evaluates 2448537Scaelto true, returns a zero (true) exit status; otherwise 2548537Scaelit returns 1 (false). 2648537ScaelIf there is no expression, test also 2748537Scaelreturns 1 (false). 2848537Scael.Pp 2948537ScaelAll operators and flags are separate arguments to the 3048537Scael.Nm test 3148537Scaelutility. 3248537Scael.Pp 3348537ScaelThe following primaries are used to construct expression: 3448537Scael.Bl -tag -width Ar 3548537Scael.It Fl b Ar file 3648537ScaelTrue if 3748537Scael.Ar file 3848537Scaelexists and is a block special 3948537Scaelfile. 4048537Scael.It Fl c Ar file 4148537ScaelTrue if 4248537Scael.Ar file 4348537Scaelexists and is a character 4448537Scaelspecial file. 4548537Scael.It Fl d Ar file 4648537ScaelTrue if 4748537Scael.Ar file 4848537Scaelexists and is a directory. 4953951Selan.It Fl e Ar file 5053951SelanTrue if 5153951Selan.Ar file 5253951Selanexists (regardless of type). 5348537Scael.It Fl f Ar file 5448537ScaelTrue if 5548537Scael.Ar file 5648537Scaelexists and is a regular file. 5748537Scael.It Fl g Ar file 5848537ScaelTrue if 5948537Scael.Ar file 6048537Scaelexists and its set group ID flag 6148537Scaelis set. 6260597Sbostic.It Fl h Ar file 6360597SbosticTrue if 6460597Sbostic.Ar file 6560597Sbosticexists and is a symbolic link. 6648537Scael.It Fl n Ar string 6748537ScaelTrue if the length of 6848537Scael.Ar string 6948537Scaelis nonzero. 7048537Scael.It Fl p Ar file 7148537ScaelTrue if 7248537Scael.Ar file 7348537Scaelis a named pipe 7448537Scael.Po Tn FIFO Pc . 7548537Scael.It Fl r Ar file 7648537ScaelTrue if 7748537Scael.Ar file exists and is readable. 7848537Scael.It Fl s Ar file 7948537ScaelTrue if 8048537Scael.Ar file 8148537Scaelexists and has a size greater 8248537Scaelthan zero. 8348537Scael.It Fl t Ar [file_descriptor] 8448537ScaelTrue if the file whose file descriptor number 8548537Scaelis 8648537Scael.Ar file_descriptor 8748537Scael(default 1) is open and is 8848537Scaelassociated with a terminal. 8948537Scael.It Fl u Ar file 9048537ScaelTrue if 9148537Scael.Ar file 9248537Scaelexists and its set user ID flag 9348537Scaelis set. 9448537Scael.It Fl w Ar file 9548537ScaelTrue if 9648537Scael.Ar file 9748537Scaelexists and is writable. 9848537ScaelTrue 9948537Scaelindicates only that the write flag is on. 10048537ScaelThe file is not writable on a read-only file 10148537Scaelsystem even if this test indicates true. 10248537Scael.It Fl x Ar file 10348537ScaelTrue if 10448537Scael.Ar file 10548537Scaelexists and is executable. 10648537ScaelTrue 10748537Scaelindicates only that the execute flag is on. 10848537ScaelIf 10948537Scael.Ar file 11048537Scaelis a directory, true indicates that 11148537Scael.Ar file 11248537Scaelcan be searched. 11348537Scael.It Fl z Ar string 11448537ScaelTrue if the length of 11548537Scael.Ar string 11619509Smckusickis zero. 11748537Scael.It Ar string 11848537ScaelTrue if 11948537Scael.Ar string 12048537Scaelis not the null 12148537Scaelstring. 12248537Scael.It Ar \&s\&1 Cm \&= Ar \&s\&2 12348537ScaelTrue if the strings 12448537Scael.Ar \&s\&1 12519509Smckusickand 12648537Scael.Ar \&s\&2 12748537Scaelare identical. 12848537Scael.It Ar \&s\&1 Cm \&!= Ar \&s\&2 12948537ScaelTrue if the strings 13048537Scael.Ar \&s\&1 13119509Smckusickand 13248537Scael.Ar \&s\&2 13348537Scaelare not identical. 13448537Scael.It Ar \&n\&1 Fl \&eq Ar \&n\&2 13548537ScaelTrue if the integers 13648537Scael.Ar \&n\&1 13719509Smckusickand 13848537Scael.Ar \&n\&2 13948537Scaelare algebraically 14048537Scaelequal. 14148537Scael.It Ar \&n\&1 Fl \&ne Ar \&n\&2 14248537ScaelTrue if the integers 14348537Scael.Ar \&n\&1 14448537Scaeland 14548537Scael.Ar \&n\&2 14648537Scaelare not 14748537Scaelalgebraically equal. 14848537Scael.It Ar \&n\&1 Fl \> Ar \&n\&2 14948537ScaelTrue if the integer 15048537Scael.Ar \&n\&1 15148537Scaelis algebraically 15248537Scaelgreater than the integer 15348537Scael.Ar \&n\&2 . 15448537Scael.It Ar \&n\&1 Fl \&ge Ar \&n\&2 15548537ScaelTrue if the integer 15648537Scael.Ar \&n\&1 15748537Scaelis algebraically 15848537Scaelgreater than or equal to the integer 15948537Scael.Ar \&n\&2 . 16048537Scael.It Ar \&n\&1 Fl \< Ar \&n\&2 16148537ScaelTrue if the integer 16248537Scael.Ar \&n\&1 16348537Scaelis algebraically less 16448537Scaelthan the integer 16548537Scael.Ar \&n\&2 . 16648537Scael.It Ar \&n\&1 Fl \&le Ar \&n\&2 16748537ScaelTrue if the integer 16848537Scael.Ar \&n\&1 16948537Scaelis algebraically less 17048537Scaelthan or equal to the integer 17148537Scael.Ar \&n\&2 . 17248537Scael.El 17348537Scael.Pp 17448537ScaelThese primaries can be combined with the following operators: 17548537Scael.Bl -tag -width Ar 17648537Scael.It Cm \&! Ar expression 17748537ScaelTrue if 17848537Scael.Ar expression 17948537Scaelis false. 18048537Scael.It Ar expression1 Fl a Ar expression2 18148537ScaelTrue if both 18248537Scael.Ar expression1 18348537Scaeland 18448537Scael.Ar expression2 18548537Scaelare true. 18648537Scael.It Ar expression1 Fl o Ar expression2 18748537ScaelTrue if either 18848537Scael.Ar expression1 18919509Smckusickor 19048537Scael.Ar expression2 19148537Scaelare true. 19248537Scael.It Cm \&( Ns Ar expression Ns Cm \&) 19348537ScaelTrue if expression is true. 19448537Scael.El 19548537Scael.Pp 19648537ScaelThe 19748537Scael.Fl a 19848537Scaeloperator has higher precedence than the 19948537Scael.Fl o 20048537Scaeloperator. 20153951Selan.Sh GRAMMAR AMBIGUITY 20253951SelanThe 20353951Selan.Nm test 20453951Selangrammar is inherently ambiguous. In order to assure a degree of consistency, 20553951Selanthe cases described in the 20653951Selan.St -p1003.2 , 20753951Selansection D11.2/4.62.4, standard 20853951Selanare evaluated consistently according to the rules specified in the 20953951Selanstandards document. All other cases are subject to the ambiguity in the 21053951Selancommand semantics. 21153951Selan.Sh RETURN VALUES 21248537ScaelThe 21348537Scael.Nm test 21448537Scaelutility exits with one of the following values: 21548537Scael.Bl -tag -width Ds 21648537Scael.It 0 21748537Scaelexpression evaluated to true. 21848537Scael.It 1 21948537Scaelexpression evaluated to false or expression was 22048537Scaelmissing. 22148537Scael.It >1 22248537ScaelAn error occurred. 22348537Scael.El 22448537Scael.Sh STANDARDS 22548537ScaelThe 22648537Scael.Nm test 22748537Scaelfunction is expected to be 22850790Scael.St -p1003.2 22950790Scaelcompatible. 230