[root@localhost log]# var=/dir1/dir2/file.txt
[root@localhost log]# echo ${var##*/}
file.txt
2、提取后缀
[root@localhost log]# echo ${var##*.}
txt
3、提取不带后缀的文件名,分两步
[root@localhost log]# tmp=${var##*/}
[root@localhost log]# echo $tmp
file.txt
[root@localhost log]# echo ${tmp%.*}
shell实战(二) 提取文件全路径的不后缀的文件名
最新推荐文章于 2025-06-13 11:45:43 发布
这篇博客介绍了Linux shell脚本中如何提取文件路径、后缀和文件名,以及如何遍历目录获取.sh文件。内容包括使用`${var##*/}


1124

被折叠的 条评论
为什么被折叠?



