Skip to content

Instantly share code, notes, and snippets.

@bench
Created February 7, 2018 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bench/d1157d91b705e207e59907b64401b6eb to your computer and use it in GitHub Desktop.
Save bench/d1157d91b705e207e59907b64401b6eb 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