GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
IF(1) General Commands Manual IF(1)

if - conditional command

if [expression [command [arg ...]]]

If evaluates the specified expression, and if its value is true, returns a zero exit status or executes the specified command with the given arguments. Otherwise, it returns a non-zero exit status. When expression is not specified, if also returns a non-zero exit status.

The following primaries are used to construct expression:

{ command [arg ...] }
The specified command is executed with the given arguments to obtain its exit status. A zero status is true; a non-zero status is false.
True if file exists and is a directory.
True if file exists.
True if file exists and is a regular file.
True if file exists and is a symbolic link.
True if the length of string is non-zero.
True if file exists and is readable.
True if file exists and has a size greater than zero bytes.
True if the file whose file descriptor number is fildes is open and associated with a terminal device. Fildes must be a decimal digit (0 - 9).
True if file exists and is writable.
True if file exists and is executable, or if file is a searchable directory.
True if the length of string is zero.
True if file1 and file2 both exist and refer to the same file (same device, same inode).
True if file1 and file2 both exist and last data-modification time of file1 is newer than that of file2.
True if file1 and file2 both exist and last data-modification time of file1 is older than that of file2.
True if the strings s1 and s2 are not equal.
Is a synonym for =.
True if the strings s1 and s2 are equal.
True if the string s1 comes before s2 according to their ASCII character values.
True if the string s1 comes after s2 according to their ASCII character values.
True if the integers n1 and n2 are algebraically equal.
True if the integers n1 and n2 are not algebraically equal.
True if the integer n1 is algebraically greater than the integer n2.
True if the integer n1 is algebraically greater than or equal to the integer n2.
True if the integer n1 is algebraically less than the integer n2.
True if the integer n1 is algebraically less than or equal to the integer n2.

These primaries may also be combined with the following operators:

! expression
unary negation operator
binary and operator
binary or operator
( expression )
parentheses for grouping

-a has higher precedence than -o. Notice that all of the operators and flags are separate arguments to if. Notice also that parentheses are meaningful to the shell and must be escaped.

Symbolic links are followed for all file-related primaries except -h.

The if command exits with one of the following values:

0
The expression was true (see below).
1
The expression was false or was not specified.
2
An error was detected.
125
The specified command was found but did not begin with the proper magic number or a `#!shell' sequence, and a valid shell was not specified by EXECSHELL with which to execute it.
126
The specified command was found but could not be executed.
127
The specified command was not found.

If the expression is true and if command is specified and executed, the exit status is that of the executed command.

Notice that the concept of `user environment' was not defined in Version 6 (V6) UNIX. Thus, use of the following environment variables by this port of the conditional command is an enhancement:

If set to a non-empty string, the value of this variable is taken as the path name of the shell which is invoked to execute the specified command when it does not begin with the proper magic number or a `#!shell' sequence.
If set to a non-empty string, the value of this variable is taken as the sequence of directories which is used to search for the specified command. Notice that the conditional command from Version 6 (V6) UNIX always used the equivalent of `.:/bin:/usr/bin', not PATH.

goto(1), etsh(1), tsh(1), test(1)

Etsh home page: https://etsh.nl/

The if command from Version 6 (V6) UNIX does not support the ==, <, >, -d, -e, -f, -h, -n, -s, -t, -x, -z, -ef, -nt, -ot, -eq, -ne, -gt, -ge, -lt, and -le operators.

In addition to supporting the above operators, this port also differs from the original in that the exit status returned varies according to whether the expression is true or false, as is the case with test(1).

An if command appeared as /bin/if in Version 3 (V3) UNIX.

This port of the if command is derived from Version 6 (V6) UNIX /usr/source/s1/if.c. It was written by Ken Thompson of Bell Labs. Jeffrey Allen Neitzel <jan@etsh.nl> ported and maintains it as if(1).

See either the LICENSE file which is distributed with etsh or https://etsh.nl/license/ for full details.

March 28, 2019 etsh-5.4.0

Search for    or go to Top of page |  Section 1 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.