Mnemonics such as -lt
can be said to come from original Fortran comparators such as .LT.
since the late 1950s.
Yes, the -lt
shell performs a numerical comparison of less. (Remember that in Perl, numerical comparisons are <
, etc., and string comparisons are indicated by alphabetical operators such as -lt
!)
However, in some, possibly many shells, the conversion and comparison can very well be done in a local long integer format. If you are on a 32-bit machine, the values ββyou specify exceed the 32-bit (signed) range by 10 times or so. On a 64-bit machine or with a shell using long long
everything will be fine.
Sixteen equivalents of decimal numbers: 021715402012 = 0x50E56BD1C and 021815402012 = 0x5144C9E1C; they cannot be octal because of 8. (However, if the shell interprets the leading zero as βoctalβ, then the second number is only 021 or 17 decimal, because 8 ends the octal number. However, the 64-bit shells I tested (Mac OS X 10.7.3 and RHEL 5) seemed to treat them as decimal rather than octal.)
The code example below, compiled under 64-bit, gives the following result:
021715402012 = 240565532 = 0x050E56BD1C 021815402012 = 340565532 = 0x05144C9E1C
Compiled under 32-bit, it gives the following result:
021715402012 = 2147483647 = 0x007FFFFFFF 021815402012 = 2147483647 = 0x007FFFFFFF
If it was in your shell, then the resulting -lt
behavior will be explained. You can confirm this by checking if these two values ββare -eq
; counter-intuitively, this will probably be evaluated as true under the hypothesis that you are using a 32-bit shell that limits its arithmetic to long
(32-bit) integers.
#include <stdio.h> #include <stdlib.h> int main(void) { char *array[] = { "021715402012", "021815402012" }; for (int i = 0; i < 2; i++) { int j = atoi(array[i]); long k = strtol(array[i], 0, 10); printf("%-10s = %10d = 0x%.10lX\n", array[i], j, k); } return 0; }