长度
str=‘this is a test str.‘ expr length "${str}" 结果: "19" expr "${str}" : ‘.*‘ 结果: "19"
拼接
??
截取--索引
str=‘this is a test str.‘ expr substr "${str}" 2 6 结果: "his is"
截取--子字符串
str=‘this is a test str.‘
expr "${str}" : ‘\(.*\)s is\(.*\)‘
结果: "thi"
位置
str=‘this is a test str.‘ expr "${str}" : ‘thi.‘ 结果: "4" expr "${str}" : ‘.*is*‘ 结果: "7"
模式匹配
str=‘this is a test str.‘ #开头匹配截取 expr "${str}" : ‘this\(.*\)‘ 结果:" is a test str." # 截取匹配后置 expr "${str}" : ‘.*is\(.*\)‘ 结果:" a test str." # 截取匹配前置 expr "${str}" : ‘\(.*\)test*‘ 结果:"this is a "