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 ]] ==:是否等于 !=:是否不等于 >:是...
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" ...
#!/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...
The two strings are not equal. 1. 2. 例2 我们还可以使用运算符来测试两个字符串是否不相等!=。 #!/bin/bash string1="apples" string2="oranges" if [ "$string1" != "$string2" ]; then echo "Strings are different." else echo "Strings are not 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" ...
-ne 比较第一个正整数不等于(not equal)第二个正整数 -gt 比较第一个正整数是否大于(Greate than)第二个正整数 -lt 比较第一个正整数是否小于(Lesser than)第二个正整数 -ge 比较第一个正整数是否大于等于(Greate or equal )第二个正整数 -le 比较第一个正整数是否小于等于(Lesser or equal)第二个正整...
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 //系统以bash解释器执行脚本 cd /etc/ pwd //命令语句 三. shell功能 3.1重定向 重定向输出:将命令的执行结果覆盖到目标文件 语法:df > a.txt //将磁盘信息覆盖到a.txt文件 重定向追加:uname -p >> a.txt //将处理器类型追加到a.txt...
true if the Strings are equal, case insensitive, or both null In Bash 判断字符串相等 格式1:test "$S1" = "$S2" 格式2:[ "$S1" = "$S2" ] 格式3:test "$S1" == "$S2" 格式4:[ "$S1" == "$S2" ] 格式5:[[ $S1 = $S2 ]] ...