方法1:${字符变量名:start:length} -----start从0开始
var="abcdefg"
echo ${var:0:5}
结果abcde
方法2:expr substr $字符变量名 start length -----start从1开始
var="abcdefg"
expr substr $var 1 5
结果abcde
方法3:cut -b start-end -----start从1开始
var="abcdefg"
echo ${var} | cut -b 1-5
结果abcde
方法4:此方法仅能用于路径分割
取路径:dirname ${完整路径字符串}
取文件名:basename ${完整路径字符串}
path=/home/a/test.txt
dirname ${path}
结果/home/a
basename ${path}
结果test.txt