The if program
if performs conditional execution.
Interface
In an execlineb script:
if [ -X ] [ -n ] [ -t | -x exitcode ] { prog1... } prog2...
- if reads prog1... in a block. 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 of that code.
- Else if execs into 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 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.
Notes
- 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 wrapper:
foreground { if { prog1... } prog2... } prog3...(in execlineb syntax) - if prog1... "" prog2... is equivalent to sh -c 'prog1... && exec prog2...'.
