Conditionally perform a command.

      if test-commands; then
      [elif more-test-commands; then
      [else alternate-consequents;]

The test-commands list is executed, and if its return status is zero, the consequent-commands list is executed.

If test-commands returns a non-zero status, each elif list is executed in turn, and if its exit status is zero, the corresponding more-consequents is executed and the command completes.

If `else alternate-consequents' is present, and the final command in the final if or elif clause has a non-zero exit status, then alternate-consequents is executed.

For simple comparisons, a more concise option is to use a conditional operator instead of IF.
for example
[ "$var" = "snark" ] && echo "found snark"

instead of

if [ "$var" = "snark" ];
  then echo "found snark"

The return status is the exit status of the last command executed, or zero if no condition tested true.)

if is a bash builtin command.

"Then you admit confirming not denying you ever said that?"
"NO! ... I mean Yes! WHAT?"
I'll put `maybe' - Bloom County


awk - Find and Replace text within file(s)
eval - Evaluate several commands/arguments
expr - Evaluate expressions
for - Loop command
switch - Conditionally perform a command
while - Loop command
File operators -f

Copyright © SS64.com 1999-2017
Some rights reserved