Bash 什么是${file%.*}";巴什的意思
我正在通读。公认的答案是:Bash 什么是${file%.*}";巴什的意思,bash,git-bash,Bash,Git Bash,我正在通读。公认的答案是: for file in "$path"/*; do [ -f "$file" ] || continue mv "$file" "${file%.*}" done 我不懂台词: mv "$file" "${file%.*}" 尽管阅读了大量资源,如 这里发生了什么?这是一种 “${file%.*}”表示“变量文件减去最右边期间之后的所有内容。” ${file%%.*}将引用最左边的句点 这是${%}运算符和 编辑:我对这个“删除子字符串”的
for file in "$path"/*; do
[ -f "$file" ] || continue
mv "$file" "${file%.*}"
done
我不懂台词:
mv "$file" "${file%.*}"
尽管阅读了大量资源,如
这里发生了什么?这是一种
“${file%.*}”
表示“变量文件
减去最右边期间之后的所有内容。”
${file%%.*}
将引用最左边的句点
这是${%}
运算符和
编辑:我对这个“删除子字符串”的扩展经历了一段艰难的时间,直到我注意到
#
在$
的“左侧”,而%
在右侧。参数扩展是将Bash用作脚本语言的一个重要组成部分;我建议练习。查看文档以了解更多信息
${var%Pattern},${var%%Pattern}
${var%Pattern}
从$var
中删除$Pattern
中
匹配$var
的后端
${var%%Pattern}
从$var
中删除$Pattern
中
匹配$var
的后端
它基本上是说用完整的文件名填充$file
,然后用*
的最短匹配项删除%
后面的所有内容,这将是任何扩展名
# assume you want to convert myfile.txt to myfile
$file="myfile.txt"
# move the current name to the current name excluding the shortest match of .* = .txt
mv "$file" "${file%.*}"
# expands to
mv "myfile.txt" "myfile"