Created
April 9, 2023 13:29
-
-
Save smowtion/6a30eb710f805b12b90dcfb6ff3896b8 to your computer and use it in GitHub Desktop.
Bash Comparison Operators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bash Comparison Operators | |
### Integer Comparison | |
Operator Description Example | |
-eq Is Equal To [ 100 -eq 100 ] | |
-ne Is Not Equal To [ 100 -ne 200 ] | |
-gt Is Greater Than [ 200 -gt 100 ] | |
-ge Is Greater Than Or Equal To [ 100 -ge 100 ] | |
-lt Is Less Than [ 100 -lt 200 ] | |
-le Is Less Than Or Equal To [ 100 -le 100 ] | |
== Is Equal To (( 100 == 100 )) | |
!= Is Not Equal To (( 100 != 200 )) | |
< Is Less Than (( 100 < 200 )) | |
<= Is Less Than Or Equal To (( 100 <= 100 )) | |
> Is Greater Than (( 200 > 100 )) | |
>= Is Greater Than Or Equal To (( 200 >= 100 )) | |
### String Comparison | |
Operator Description Example | |
= or == Is Equal To [ abc == abc ] | |
!= Is Not Equal To [ abc != def ] | |
> Is Greater Than (ASCII) [ def > abc ] | |
>= Is Greater Than Or Equal To [ def >= def ] | |
< Is Less Than [ abc < def ] | |
<= Is Less Than Or Equal To [ abc <= def ] | |
-n Is Not Null [ -n abc ] | |
-z Is Null (Zero Length String) [ -z "" ] | |
### File Tests | |
Operator Description Example | |
-d Directory [ -d /tmp/abc ] | |
-e Exists (also -a) [ -e /tmp/abc ] | |
-f Regular file [ -f /tmp/abc ] | |
-h Symbolic link (also -L) [ -h /tmp/abc ] | |
-p Named pipe [ -p /tmp/abc ] | |
-r Readable by you [ -r /tmp/abc ] | |
-s Not empty [ -s /tmp/abc ] | |
-S Socket [ -S /tmp/abc ] | |
-w Writable by you [ -w /tmp/abc ] | |
-N Modified since last read [ -N /tmp/abc ] | |
### File Comparison | |
Operator Description Example | |
-nt Newer Than [ /tmp/a -nt /tmp/b ] | |
-ot Older Than [ /tmp/a -ot /tmp/b ] | |
-ef Hard Link To [ /tmp/a -ef /tmp/b ] | |
#### Sources | |
- [freeseotool.org](https://freeseotool.org/) | |
- [currencyaz.com](https://currencyaz.com/) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment