What is “-le” in shell script?

笑着哭i 提交于 2019-11-29 15:43:46

-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.

As is stated in the documentation:

integer comparison

(...)

-lt: is less than

if [ "$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).

dinesh saini

-le is less than or equals to :

if [ $stage -le 2 ];

is same as:

stage <= 2
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!