[英]Extracting filename from path in bash using 'basename -s'
Can anyone explain the following code: 任何人都可以解释以下代码:
for var in $1\*.html
echo $( basename -s .html $var )
done
What does -s
do? -s
做什么的? Does it strip off the .html from each filename? 它会从每个文件名中删除.html吗?
The -s suffix
option means that basename
removes the suffix from the filename, if present. -s suffix
选项表示basename
从文件basename
删除后缀(如果存在)。
For example: 例如:
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
Not sure why you have $1\\*.html
in your for loop - that suppresses the glob expansion and just yields the file that has a literal *.html
in it. 不知道为什么在for循环中有
$1\\*.html
-抑制了全局扩展,只产生了带有文字*.html
的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.