echo "The two strings are equal." else echo "The two strings are not equal." fi 这是我们执行脚本时的结果: 代码语言:txt AI代码解释 $ ./test.sh The two strings are not equal. 例2 我们还可以使用运算符来测试两个字符串是否不相等!=。 代码语言:txt AI代码解释 #!/bin/bash string1="appl...
数值测试:数值比较 -eq:是否等于(equal) -ne:是否不等于(not equal) -gt:是否大于(greater than) -ge:是否大于等于(greater equal) -lt:是否小于(little than) -le:是否小于等于(little equal) 数值测试示例 字符串测试:字符串要用引号引起来,最好使用[[ expression ]] ==:是否等于 !=:是否不等于 >:是...
-eq相等(equal) -ne不等(not equal) -gt大于(greater than) -lt小于(less than) -ge大于等于 (greater than or equal) -le小于等于 (less than or equal) 另外,需注意crontab任务调度中,%是个特殊字符,要在前加"\"进行转义 例: 010* * * cd /home/zzh && sh test.sh $(date -d"1 day ago"...
if [ "$string1" = "$string2" ]; then echo "The two strings are equal." else echo "The two strings are not equal." fi 这是我们执行脚本时的结果: $ ./test.sh The two strings are not equal. 例2 我们还可以使用运算符来测试两个字符串是否不相等!=。 #!/bin/bash string1="apples" ...
The two strings are not equal. 1. 2. 例2 我们还可以使用运算符来测试两个字符串是否不相等!=。 AI检测代码解析 #!/bin/bash string1="apples" string2="oranges" if [ "$string1" != "$string2" ]; then echo "Strings are different." ...
#!/bin/bash num1=20 num2=30 num3=20 if [ $num1 -eq $num3 ]; then echo "num1 is equal to num3" else echo "num1 is not equal to num3" fi if [ $num2 -ne $num1 ]; then echo "num2 is not equal to num1" else echo "num2 is equal to num1" ...
NOTE:Every bash shell script in this tutorial starts withshebang:"#!"which is not read as a comment. First line is also a place where you put your interpreter which is in this case: /bin/bash. Here is our first bash shell script example: ...
/bin/bash # this is check crond # by author rivers on 2021-9.23 # 定义一个变量名 name=crond num=$(ps -ef|grep $name|grep -vc grep) if [ $num -eq 1 ];then echo "$num running!" else echo "$num is not running!" fi
/bin/bash num1=10 num2=20 if [ $num1 -eq $num2 ] then echo “$num1 is equal to $num2” else echo “$num1 is not equal to $num2” fi “` 在上述示例中,如果`$num1`的值等于`$num2`,则输出”$num1 is equal to $num2″;否则,输出”$num1 is not equal to $num2″。
#!/bin/bash num1=10 num2=20 if [ $num1 -eq $num2 ]; then echo "Numbers are equal." else echo "Numbers are not equal." fi if [ $num1 -ne $num2 ]; then echo "Numbers are indeed not equal." else echo "Numbers are equal." fi 在这个示例中,第一个 if 语句检查 num1 和nu...