从完整文件名中提取文件名
#!/bin/bash
FILES=src/*.erl
shopt -s nullglob
for f in $FILES
do
echo "Processing $f file..."
# ???
done
如何从完整路径中提取文件名? “pathfilename=${f%.*}”是什么意思?
#!/bin/bash
FILES=src/*.erl
shopt -s nullglob
for f in $FILES
do
echo "Processing $f file..."
# ???
done
How i can extract file name from full path? And what does it mean - "pathfilename=${f%.*}"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将复制帮助输出,因为它有示例和所有内容。
I'll just copy the help-output, since it has examples and everything.
更新:我已经删除了对第一部分的回答,因为显然我误解了所问的内容。
您提到的语法,
pathfilename=${f%.*}
,表示pathfilename
设置为$f
的值,并从字符串末尾删除.*
的最短可能匹配项。这将从文件名中去除扩展名。 bash 手册对此语法的描述如下 :Update: I've removed my answer to the first part, since apparently I misunderstood what was being asked.
The syntax you mention,
pathfilename=${f%.*}
, means thatpathfilename
is set to the value of$f
with the shortest possible match for.*
removed from the end of the string. This will strip the extension from the filename. The bash manual describes this syntax as follows: