double brackets

Bash's double-bracket test, [[ and ]], a keyword that does not split words or expand globs and adds pattern and regular expression matching.

In more detail

An empty variable inside [[ ]] stays an empty string instead of disappearing, so comparisons do not break. == compares against a glob pattern, as in [[ $file == *.txt ]], and =~ against a regular expression. It is not available in POSIX sh.

Example

if [[ "$file" == *.txt ]]; then echo "text file"; fi

Related terms

Taught in

References