-
-
Save antonioiksi/7f24b9472f08aa0423ba4c2d8c4b4bbf to your computer and use it in GitHub Desktop.
conditions syntax in bash
This file contains 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
## check the return of a command | |
if command; then | |
[...] | |
fi | |
## check by string comparison / numerical / file existence / or more | |
if [[ CHECK ]]; then | |
[...] | |
fi | |
# CHECK can be one of : | |
# string1 = string2 => string are equals | |
# string1 != string2 => string are not equals | |
# val1 -eq val2 => numbers are equals | |
# val1 -neq val2 => numbers are not equals | |
# val1 -gt val2 => val1 is greater than val2 | |
# val1 -gte val2 => val1 is greater than or equal to val2 | |
# val1 -lt val2 => val1 is lower than val2 | |
# val1 -lte val2 => val1 is lower than or equal to val2 | |
# etc etc | |
# all comparator can be found with `man test` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment