conditional-operator

Bash < — lexicographic ordering

Compares strings using the current locale, not numeric magnitude. In the test/[ builtin, the operator must be protected from shell redirection and Bash uses ASCII ordering in its usual non-POSIX mode. The example fixes C locale. Run the example independently in a fresh private directory. Expected output (one item per line): lexical=0; numeric=1.

Formal Syntax & Structure

bash syntaxbash
[[ left < right ]]

Parameters & Attributes

NameTypeDescription
leftstringFirst string.
rightstringSecond string.

Return Value

exit status

0 for a true condition; 1 for a false condition. Invalid expressions may fail differently.

Working Example

Example Snippetbash
export LC_ALL=C[[ 10 < 2 ]]; printf 'lexical=%s\n' "$?"[[ 10 -lt 2 ]]; printf 'numeric=%s\n' "$?"
Bash Reference