格式一:{string:position} 从名称为${string}的字符串的第$position个位置开始抽取子串,从0开始标号。 格式二:{string:position:length} 增加$length变量,表示从${string}字符串的第$position个位置开始抽取长度为$length的子串。 需要注意:都是从string的左边开始计数抽取子串。 示例: [root@kevin ~]# string="...
$string1 != $string2表示两个字符串是否不相等。 -z $string表示字符串string是否为空。 -n $string表示字符串string是否不为空。 测试数字: $num1 -eq $num2equal的缩写,表示两个数字是否相等。 $num1 -ne $num2not equal的缩写,表示两个数字是否不相等。 $num1 -lt $num2lower than的缩写,表示num...
排在string2之前,则为真 [ string1 \> string2 ] #如果string1在本地的字典序列中排在string2之后,则为真 #判断整数 ,在[[]] 可以使用替换字符 (0~9可以,但是超出后建议使用 -nn 形式比较) #建议采用 (()) 两个形式都通用 -eq:等于(equal) # 可采用 == 或= 替代-ne:不等于(not equal) # ...
[ STRING1 != STRING2 ] 如果字符串不相同则返回为真 [ STRING1 < STRING2 ] 如果 “STRING1”字典排序在“STRING2”前面则返回为真。 [ STRING1 > STRING2 ] 如果 “STRING1”字典排序在“STRING2”后面则返回为真。 If [ $a = $b ] 如果string1等于string2 字符串允许使用赋值号做等号 if [ $...
expr length $string # 方式 2 expr "$string" : '.*' # 方式 3 # 具体实例 str="hello world" echo "After using #str : ${#str}" echo "Use expr length : $(expr length "$str")" # 该方式不建议使用,因为shellcheck也建议使用第一种方式 ...
-eqequal,检测两个数是否相等,相等返回 true。[ $a -eq $b ] 返回 false。-nenot equal,检测...
负向预查,在任何不匹配Negative lookahead matches the search string at any point where a string not matching pattern 的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。例如’Windows (?!95|98|NT|2000)’ 能匹配 “Windows 3.1” 中的 “Windows”,但不能匹配 ...
Make sure when you type backtick character, it is not the single quotation mark. You must enclose the command with two backticks like this: mydir=`pwd` Or the other way: mydir=$(pwd) So the script could be like this: #!/bin/bash ...
负向预查,在任何不匹配Negative lookahead matches the search string at any point where a string not matching pattern 的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。例如’Windows (?!95|98|NT|2000)’ 能匹配 “Windows 3.1” 中的 “Windows”,但不能匹配 ...
This script calculates the square of 5. ' ((area=5*5)) echo$area 注意多行注释是如何放置在内部的:“和”字符。 5.While循环 while循环构造用于多次运行某些指令。查看以下名为while.sh的脚本,以更好地理解此概念。 #!/bin/bash i=0 while[$i-le 2 ] ...