Shell从带路径的字符串中获取文件名


var1=/usr/lib/abcdefg.so.bak
var2=/usr/sbin/ifconfiggg
all_name=`basename $var1`
sub_name1=`basename $var1 .bak`
sub_name2=`basename $var2 gg`

echo "all_name: $all_name" #all_name: abcdefg.so.bak
echo "sub_name1: $sub_name1" #sub_name1: abcdefg.so
echo "sub_name2: $sub_name2" #sub_name2: ifconfig

This entry was posted in Shell.