2
我有這些文件的文件名:添加擴展使用shell
image01
landscape.jpg
.
.
macro01
macro02
我想寫驗證是否該文件有任何擴展名的shell腳本;如果不是,它將添加jpg
擴展名。
我有這些文件的文件名:添加擴展使用shell
image01
landscape.jpg
.
.
macro01
macro02
我想寫驗證是否該文件有任何擴展名的shell腳本;如果不是,它將添加jpg
擴展名。
for file in "[email protected]"
do
case "$file" in
*.*) : Already has an extension;;
*) mv "$file" "$file.jpg";;
esac
done
如果要檢測.jpg
作爲擴展名,改變*.*
到*.jpg
(和修復結腸命令的解說)。
我想你想要做的是檢查文件是否有.jpg
擴展名,否則根據需要添加擴展名。 試着做一些與此類似:
if [[ $file =~ \.jpg$ ]]; then
echo "has jpg ext";
else
echo "no jpg ext";
fi;
編輯:如果你要處理多個擴展名,然後看看Jonathan Leffler's
答案。
「我想編寫一個shell腳本來驗證文件是否有擴展名,如果不是則會添加jpg文件。」世界上你的牡蠣,去爲它! – Johnsyweb