Koskamo

Conditional constructs: if, case, ((…)), and [[…]]

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

if executes its test-commands and runs the consequent commands when their return status is zero; elif lists are tried in turn, else runs when no condition tested true, and the return status is that of the last command executed or zero if no condition tested true. case executes the command-list of the first pattern matching its word; clauses end with ;;, ;&, or ;;& — ;& continues into the next clause's command-list, while ;;& retests the next clause's patterns — and a final * pattern is the common idiom for a default case because it always matches. (( expression )) evaluates arithmetic and returns status 0 when the value is non-zero, 1 otherwise. [[ expression ]] evaluates a conditional expression without word splitting or filename expansion on its words, while tilde expansion, parameter and variable expansion, arithmetic expansion, command substitution, process substitution, and quote removal still occur; with == and != the string to the right is matched as a pattern, = is identical to ==, and < and > sort lexicographically using the current locale. Scope: Bash. Reviewed October 4, 2026.

Source and provenance

Original source
www.gnu.org
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.