Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The -lt operator is a binary integer comparison operator in Bash that evaluates whether the numerical value of the left operand is strictly less than the numerical value of the right operand. It yields an exit status of 0 (true) if the condition is satisfied, and 1 (false) otherwise.

Syntax

[ INT1 -lt INT2 ]
[[ INT1 -lt INT2 ]]
test INT1 -lt INT2

Technical Characteristics

  • Data Type Restriction: The -lt operator is strictly reserved for integer evaluation. Because Bash does not natively support floating-point arithmetic, attempting to evaluate floats (e.g., 1.5 -lt 2) using [ ] or test results in a standard runtime error (integer expression expected). Conversely, attempting the same within the [[ ]] keyword results in a syntax error (syntax error: invalid arithmetic operator).
  • Algebraic Evaluation: The operator correctly evaluates signed integers. Negative values are processed algebraically, meaning -10 -lt -5 evaluates to true (0).
  • Operator Distinction: -lt must not be confused with the < operator. The -lt operator compares numerical values, whereas < performs lexicographical (ASCII/locale-based) string comparison.
  • Execution Contexts & Error Handling:
    • [ ] (POSIX test command): Operands undergo word splitting and pathname expansion. If an operand is a quoted empty string or a non-numeric string, the command throws a non-fatal runtime integer expression expected error to stderr and returns an exit status of 2. Script execution will continue normally unless set -e is explicitly enabled. If an unquoted null variable is used (e.g., [ $nullvar -lt 5 ]), word splitting strips the variable out entirely before evaluation, resulting in a unary operator expected error instead.
    • [[ ]] (Bash Extended Test Keyword): Operands are parsed as a single construct without word splitting, preventing the unary operator expected error associated with unquoted null variables. However, passing non-numeric strings to -lt inside [[ ]] forces Bash to attempt arithmetic evaluation. Unrecognized strings are often implicitly evaluated as 0, which suppresses runtime errors but introduces silent logical failures.
Master Bash with Deep Grasping Methodology!Learn More