Bash - If then else

Bash Liste Des Attaques Ovh


if execute conditionally a block with a list of command based on the exit status of a list of command


if list; then 
[ elif list; then list; ]... 
[ else list; ] 
  • The if list. The command list) is executed (Generally there is one or more conditional command expression in the list of command)
  • If its exit status is:
    • zero, then the then list list is executed.
    • Otherwise, each elif list list is executed in turn, and if its exit status is zero:
      • the corresponding then list list is executed and the if command completes.
      • Otherwise, the else list list is executed, if present.

Nested if example

if lists;
  if lists;
     # code if 'expression' is true.

Exit Status

The exit status of the entire construct is:

  • the exit status of the last command executed,
  • or zero if no condition tested true.


With a conditional expression command

if [ "foo" = "foo" ]; then
   echo expression evaluated as true
    echo expression evaluated as false

Documentation / Reference

help if

Discover More
Bash Liste Des Attaques Ovh
Bash - Conditional Expression

A predicate or boolean expression is known in Bash as a Conditional Expression. It is a command that returns an exit status of 0 or 1. The conditional expression is part of the compound expression. ...
Bash Liste Des Attaques Ovh
Bash - Flow statement (Control Structure)

Bash - Flow statement (Control Structure) The words that control the flow of statement (ie condition and loop). help * * * * * * see * * ...
Bash Liste Des Attaques Ovh
Bash - Parameter

A variable in bash is called a parameter. There is three different type of parameter variables: referenced by a name (Ex: ${myVariable}) positional parameters (ie command/script arguments): referenced...
Card Puncher Data Processing
Datacadamia - Data all the things

Computer science from a data perspective

Share this page:
Follow us:
Task Runner