execline: the ifelse command
Keywords: execline command ifelse

execline
Software
skarnet.org

# The `ifelse` program

`ifelse` performs conditional execution, with two branches.

## Interface

In an execlineb script:

         ifelse [ -X ] [ -n ] { prog1... } { prog2... } prog3...

- `ifelse` reads prog1... in a block. It forks and executes it, then waits for it to complete.
- If prog1 crashes, `ifelse` prints an error message and exits 128 plus the number of the signal that killed prog1.
- If prog1 exits with a return code equal to 0, `ifelse` execs into prog2.
- Else `ifelse` execs into prog3.

## Options

- `-n` : negate the test.
- `-X` : do not die if prog1 crashes; treat a crash as a non-zero ("false") exit.

## Notes

- `ifelse prog1... "" prog2... "" prog3...` is roughly equivalent to `sh -c 'prog1... && exec prog2... || exec prog3...'`.