IF(1)

NAME
if - perform conditional execution

SYNOPSIS
In an execlineb(1) script:

if [-X] [-n] [-t | -x exitcode] { prog1... } prog2...

DESCRIPTION
if reads prog1... in a block ( cf. execline-block(7)). It forks and executes it, then waits for it to complete.

If prog1 crashes, if prints an error message then exits 128 plus the number of the signal that killed prog1.

If prog1 exits with a non-zero code, if exits with an approximation ( cf. execline-exitcodes(7)) of that code.

Else if exec(3) s into prog2.

if will exit if prog1... exits false. To use it in an execline script that must run prog3... no matter the result of the test, use a foreground(1) wrapper:

    foreground { if { prog1... } prog2... } prog3...

(in execlineb(1) syntax).

‘if prog1... "" prog2...’ is equivalent to ‘sh -c 'prog1... && exec prog2...'’.

OPTIONS

-X  Treat a crash of prog1 as a non-zero ( “false”) exit. This is mostly useful in combination with -n.

-n  Negate the test. If prog1 exits true, then if will exit 1; else it will exec(3) into prog2.

-x exitcode
    If if needs to exit, it will exit exitcode instead of whatever else it would have exited.

-t  If if needs to exit, it will exit 0. This is equivalent to ‘-x 0’.

SEE ALSO
background(1), backtick(1), execlineb(1), foreground(1), ifelse(1), ifte(1), ifthenelse(1), pipeline(1), runblock(1), exec(3), execline-block(7)

This man page is ported from the authoritative documentation at: https://skarnet.org/software/execline/if.html

AUTHORS
Laurent Bercot Alexis <flexibeast@gmail.com> (man page port)