Bash Conditional Expressions

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • [[ -OP $filename ]]
  • [[ $file1 -OP $file2 ]]
  • [[ -z $string ]]
  • [[ -n $string ]]
  • [[ "$string1" == "$string2" ]]
  • [[ "$string1" == $pattern ]]

Remarks

The [[ … ]] syntax surrounds bash built-in conditional expressions. Note that spaces are required on either side of the brackets.

Conditional expressions can use unary and binary operators to test properties of strings, integers and files. They can also use the logical operators &&, || and !.



Got any Bash Question?