summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/cheatsheets/bash.md54
1 files changed, 47 insertions, 7 deletions
diff --git a/content/cheatsheets/bash.md b/content/cheatsheets/bash.md
index 224a153..54c9bb6 100644
--- a/content/cheatsheets/bash.md
+++ b/content/cheatsheets/bash.md
@@ -3,12 +3,52 @@ title = "bash"
disable_share = true
+++
-This is a cool bash snippet.
+# Test operators
-```bash
-#!/bin/bash
+## String
-if [ "$1" -eq 1 ]; then
- exit 4
-fi
-```
+|op | desc | example |
+|---|--------------------------------------------|-------------------------------------------|
+|= |is equal to |`if [ "$a" = "$b" ]` |
+|== |is equal to |`if [ "$a" == "$b" ]` |
+|!= |is not equal to |`if [ "$a" != "$b" ]` |
+|< |is less than, in ASCII alphabetical order |`if [[ "$a" < "$b" ]]; if [ "$a" \< "$b" ]`|
+|> |is greater than, in ASCII alphabetical order|`if [[ "$a" > "$b" ]]; if [ "$a" \> "$b" ]`|
+|-z |string is null, that is, has zero length |`if [ -z "$a" ]` |
+
+## Integer
+
+|op | desc | example |
+|---|-------------------------------------------------------|----------------------|
+|-eq|is equal to |`if [ "$a" -eq "$b" ]`|
+|-ne|is not equal to |`if [ "$a" -ne "$b" ]`|
+|-gt|is greater than |`if [ "$a" -gt "$b" ]`|
+|-ge|is greater than or equal to |`if [ "$a" -ge "$b" ]`|
+|-lt|is less than |`if [ "$a" -lt "$b" ]`|
+|-le|is less than or equal to |`if [ "$a" -le "$b" ]`|
+|< |is less than (within double parentheses) |`(("$a" < "$b"))` |
+|<= |is less than or equal to (within double parentheses) |`(("$a" <= "$b"))` |
+|> |is greater than (within double parentheses) |`(("$a" > "$b"))` |
+|>= |is greater than or equal to (within double parentheses)|`(("$a" >= "$b"))` |
+
+## File
+
+| op | desc | example |
+|---------|----------------------------------------------------------------------------------|-----------------------|
+|-h |file is a symbolic link |`if [ -h "$f" ]` |
+|-L |file is a symbolic link |`if [ -L "$f" ]` |
+|-S |file is a socket |`if [ -S "$f" ]` |
+|-t |file (descriptor) is associated with a terminal device |`if [ -t "$f" ]` |
+|-r |file has read permission (for the user running the test) |`if [ -r "$f" ]` |
+|-w |file has write permission (for the user running the test) |`if [ -w "$f" ]` |
+|-x |file has execute permission (for the user running the test) |`if [ -x "$f" ]` |
+|-g |set-group-id (sgid) flag set on file or directory |`if [ -g "$f" ]` |
+|-u |set-user-id (suid) flag set on file |`if [ -u "$f" ]` |
+|-k |sticky bit set |`if [ -k "$f" ]` |
+|-O |you are owner of file |`if [ -O "$f" ]` |
+|-G |group-id of file same as yours |`if [ -G "$f" ]` |
+|-N |file modified since it was last read |`if [ -N "$f" ]` |
+|f1 -nt f2|file f1 is newer than f2 |`if [ f1 -nt f2 "$f" ]`|
+|f1 -ot f2|file f1 is older than f2 |`if [ f1 -ot f2 "$f" ]`|
+|f1 -ef f2|files f1 and f2 are hard links to the same file |`if [ f1 -ef f2 "$f" ]`|
+|! |"not" -- reverses the sense of the tests above (returns true if condition absent).|`if [ ! "$f" ]` |