Interview Prep/Shell Scripting/Arrays, conditionals and loops

What are the string and integer comparison operators in `[[ ]]` and `[ ]`?

BeginnerConceptArrays, conditionals and loops
Answer

Strings: == / = (equal), !=, < / > (sort order), -z (empty), -n (non-empty). Integers in [ ]/[[ ]]: -eq -ne -lt -le -gt -ge.

[[ $env == prod ]]
[[ -z ${TOKEN:-} ]] && die "TOKEN is empty"
[[ $count -gt 10 ]]        # integer compare
[[ $count > 10 ]]          # STRING compare: "9" > "10" is true!
(( count > 10 ))           # clearest for numbers

Mixing them up is a classic bug: > inside [[ ]] compares lexicographically, and inside [ ] it is a redirection that creates a file named 10.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Arrays, conditionals and loops