Shell Programming/If

From Wikibooks, open books for an open world
Jump to navigation Jump to search


The if statement has the following basic structure:

  if [ condition of expressions ]; then
  fi


Using && and || in control statements[edit | edit source]

The && and || can be used in control statements to represent nested loops like:

  if [ condition1 ]; then
     if [ condition 2 ]; then
     fi
  fi

as:

  if [ condition1 ] && [ condition2 ]; then
  fi