计算字符串长度
image.pngvar5="/usr/local/Cellar/dart/2.5.2/bin:/Users/lihe/Downloads/flutter/bin"
echo ${#var5}
输出结果 66
var5="/usr/local/Cellar/dart/2.5.2/bin:/Users/lihe/Downloads/flutter/bin"
var6=`expr ${#var5}`
echo $var6
输出结果 66
提取字符串
1 ${字符串变量:提取位置:提取长度}
var1="i love you, do you love me"
var2=${var1:2:10}
echo $var2
输出结果
love you,
2 ${字符串变量:提取位置} 从index开始提取到最后
var1="i love you, do you love me"
var2=${var1:2}
echo $var2
输出结果
love you, do you love me
3 ${字符串变量:-提取位置} 从最后面的index开始向前提取
var1="i love you, do you love me"
var2=${var1:-2}
echo $var2
输出结果
i love you, do you love me
网友评论