TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
-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
Technical Characteristics
- Data Type Restriction: The
-ltoperator 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[ ]ortestresults 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 -5evaluates to true (0). - Operator Distinction:
-ltmust not be confused with the<operator. The-ltoperator compares numerical values, whereas<performs lexicographical (ASCII/locale-based) string comparison. - Execution Contexts & Error Handling:
[ ](POSIXtestcommand): 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 runtimeinteger expression expectederror to stderr and returns an exit status of2. Script execution will continue normally unlessset -eis 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 aunary operator expectederror instead.[[ ]](Bash Extended Test Keyword): Operands are parsed as a single construct without word splitting, preventing theunary operator expectederror associated with unquoted null variables. However, passing non-numeric strings to-ltinside[[ ]]forces Bash to attempt arithmetic evaluation. Unrecognized strings are often implicitly evaluated as0, which suppresses runtime errors but introduces silent logical failures.
Master Bash with Deep Grasping Methodology!Learn More





