Bash [[ ]] Double Brackets
[[ ]] is the Bash version of the [ ] test, with extra features.
It can match patterns with == and =~, combine tests with && and || inside the brackets, and an empty variable does not break it, even without quotes.
Match a pattern
Save this as files.sh:
#!/bin/bash
file="report.txt"
if [[ $file == *.txt ]]; then
echo "$file is a text file"
fi
if [[ $file =~ ^re ]]; then
echo "$file starts with re"
fi
Run it:
./files.sh
report.txt is a text file
report.txt starts with re
Combine two tests
age=25
[[ $age -ge 18 && $age -lt 65 ]] && echo "Working age"
Working age