$var=/dir1/dir2/file.txt $a=${var##*/} file.txt $b=${a%.*} file 其中 #:表示从左边算起第一个 %:表示从右边算起第一个 ##:表示从左边算起最后一个 %%:表示从右边算起最后一个