Skip to main content

Bash Cheat Sheet

Comparison operators

 Operator  Description   Operator Description
-eq Is equal to   -n Is not null
-ne Is not equal to   -z Is null
-gt Is greater than   -r file exists and is readable by the user
-ge Is greater than or equal to   -e file exists
-lt Is less then    -f  file is a regular file (not directory or other special type)
-le Is less than or equal to    -s   file size is greater then 0
== is equal to    -x  file is executable by the user
!= is not equal to    -w  file is writable by the user
< Is less than    !  negates the operator
<= Is less than or equal to      
> Is greater then      
>= Is greater than or equal to      

Variables for script arguments

 Variable  Description   Variable Description
$1 ... $n Argument number   $# Number of arguments
$0 Name of the file   $? Return value (0 = ok, > 0 = error)
$* List of arguments