What is "-le" in shell script?
Solution 1
-le
in Linux means less that or equal to i.e. <=
Means
-le
checks if the value of left operand is less than or equal to (<=
) the value of right operand, if yes then condition becomes true.
consider:
$a=10
$b=20
then [ $a -le $b ]
is true.
Solution 2
As is stated in the documentation:
integer comparison
(...)
-lt
: is less thanif [ "$a" -lt "$b" ]
So it interprets the values of $a
and $b
(in your case $stage
and 2
) as integers and performs a comparison. If the first element is less than or equal to the second, the test succeeds and the then
part will be executed.
As the documentation later states, one can use <=
as well:
<=
: is less than or equal to (within double parentheses)(("$a" <= "$b"))
But then one uses double parentheses (as specified in the documentation).
Solution 3
-le
is less than or equals to :
if [ $stage -le 2 ];
is same as:
stage <= 2
udani
Updated on June 04, 2022Comments
-
udani almost 2 years
I am going through this code. I would like to know what is meant by
-le
in the following code segment.if [ $stage -le 2 ]; then
In one of the questions it says that
-le
stands for<=
of strings, but that is in Perl. Is it the same here as well?Further, I would like to know if that
$stage
variable automatically gets updated. It has been initialized to0
at the beginning, but later, how does that get incremented?