-le:小于等于(less than or equal to) 以下是一个比较两个数字并输出结果的例子: #!/bin/bash a=10 b=20 if [ $a -eq $b ] then echo "a等于b" else echo "a不等于b" fi 输出结果为: a不等于b 分支处理 在Bash中,我们可以使用if-elif-else语句来进行分支处理。以下是一个根据输入的数字输出...
-ge:大于等于(greater than or equal to) -le:小于等于(less than or equal to) -eq:等于(equal to) -ne:不等于(not equal to) 下面是一个数字比较的例子: 代码语言:txt 复制 num1=10 num2=20 if [ $num1 -gt $num2 ]; then echo "num1 is greater than num2" else echo "num1 is less...
-eq:等于 (equal to) -ne:等于 (not equal to) -gt:大于 (greater than) -ge:大于或等于(greater than or equal to) -lt:小于 (less than) -le:小于或等于(less than or equal to) #!/usr/bin/env bash test 1 -eq 2 && echo "true" || echo "false" test 1 -ne 2 && echo "true" ...
-eq:等于 (equal to) -ne:等于 (not equal to) -gt:大于 (greater than) -ge:大于或等于(greater than or equal to) -lt:小于 (less than) -le:小于或等于(less than or equal to) #!/usr/bin/env bash test 1 -eq 2 && echo "true" || echo "false" test 1 -ne 2 && echo "true" ...
Greater than or equal to -eq Equal to -ne Not equal toAnd as with string comparisons, the arithmetic test returns a result of true or false; 0 if true, 1 otherwise. So, for example, [ 3 -gt 2 ] produces exit status 0, as does [ \( 3 -gt 2 \) || \( 4 -le 1 \) ...
statements to run fi 关键字 then 被认为是一个分隔命令,需要一个分号将其和 if 命令分隔开,关键字 fi 表示 if 命令的结束。 例如: test –f 命令检查某个文件是否存在: if test -f ./report.out ; then printf “The report file ./report.out exists!\n” ...
Bash provides several conditionals that you can use within if statements: 1. Numeric Comparisons: -eq: Equal to -ne: Not equal to -gt: Greater than -lt: Less than -ge: Greater than or equal to -le: Less than or equal to 2. String Comparisons: ...
>= - is greater than or equal to - (("$a" >= "$b")) Examples: [ n1 -eq n2 ] (true if n1 same as n2, else false) [ n1 -ge n2 ] (true if n1greater then or equal to n2, else false) [ n1 -le n2 ] (true if n1 less then or equal to n2, else false) ...
How to do string comparison and check if a string equals to a value? How to check if a string is in an array? How to use the Bash ternary operator? How to negate an if condition in a Bash if statement? (if not command or if not equal) How to use the BASH_REMATCH variable with...
&&,||,!Logical AND, OR, and negation. &,|,^,~Bitwise AND, OR, XOR, and negation. <=,<,>,=>Less than or equal to, less than, greater than, and greater than or equal to comparison operators. ==,!=Equality and inequality comparison operators. ...