Skip to content

Instantly share code, notes, and snippets.

@megamcloud
Forked from bench/condition_syntax_bash.sh
Created July 26, 2018 10:43
Show Gist options
  • Save megamcloud/052b63b372e86f1ef80f97c2cd2aa0ab to your computer and use it in GitHub Desktop.
Save megamcloud/052b63b372e86f1ef80f97c2cd2aa0ab to your computer and use it in GitHub Desktop.
conditions syntax in bash
## 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