gpt4 book ai didi

linux - 使用 'basename -s' 从 bash 中的路径中提取文件名

转载 作者:太空宇宙 更新时间:2023-11-04 10:11:05 25 4
gpt4 key购买 nike

谁能解释一下下面的代码:

for var in $1\*.html
echo $( basename -s .html $var )
done

-s 有什么作用?它会去掉每个文件名中的 .html 吗?

最佳答案

-s suffix 选项意味着 basename 从文件名中删除后缀(如果存在)。

例如:

file=path/to/file.html
basename "$file" => yields file.html
basename -s .html "$file" => yields file
basename -s html "$file" => yields file.
basename -s .txt "$file" => yields file.html since the string has no .txt extension

不确定为什么你的 for 循环中有 $1\*.html - 这会抑制 glob 扩展并只生成具有文字 *.html 的文件

关于linux - 使用 'basename -s' 从 bash 中的路径中提取文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49081911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com