[Bash] Test whether a string ends with a suffix

Created on November 30, 2026

Use pattern matching in [[ ... ]] to test for a suffix. In *.csv, * matches any leading text, so the expression is true when the value ends in .csv.

file="report.csv"

if [[ "$file" == *.csv ]]; then
  echo "CSV file"
fi

Output

CSV file
Bash Shell command