首页 > 解决方案 > 从脚本变量中提取文件名

问题描述

我有一个批处理文件,例如

for f in bin/$1*.txt; do echo $f; done

我想只回显文件名 - 而不是 bin/temp.txt 或 temp.txt - 只是 temp。

如何从 $f 中提取文件名?

标签: bashmacos

解决方案


如果后缀始终相同,则可以使用basename -s ".txt" $f.


推荐阅读