Bash test operators, if, case, loops, functions, arrays, here-documents, traps and set options.
40 cards · basic cards · AI-written, checked twice. Edit anything.
- What does [ -z STRING ] test?
Show answer
Whether STRING is empty
- What does [ -n STRING ] test?
Show answer
Whether STRING is non-empty
- What does [ -f FILE ] test?
Show answer
Whether FILE is a regular file
- What does [ -d DIR ] test?
Show answer
Whether DIR is a directory
- What does [ -e FILE ] test?
Show answer
Whether FILE or directory exists
- What does [ -r FILE ] test?
Show answer
Whether FILE is readable
- What does [ $a -eq $b ] test?
Show answer
Whether $a equals $b numerically
- What does [ $a -lt $b ] test?
Show answer
Whether $a is less than $b
- What does [ $a -gt $b ] test?
Show answer
Whether $a is greater than $b
- What does [ $a -ge $b ] test?
Show answer
Whether $a is greater than or equal to $b
- What does [ "$a" = "$b" ] test?
Show answer
Whether strings are equal
- What does [ condition1 -a condition2 ] test?
Show answer
Whether both conditions are true (AND)
- What does [ condition1 -o condition2 ] test?
Show answer
Whether either condition is true (OR)
- When should you use [[ ]] instead of [ ]?
Show answer
For regex matching, to avoid word splitting, or easier quoting of variables
- How do you write if with an else clause?
Show answer
if CONDITION; then COMMANDS; else COMMANDS; fi