我需要檢查圖像是否有900x900像素的分辨率和文件名不允許包含_thumb或_V巴什腳本IF條件
我試圖用這個做line:
如果圖片的像素爲900x900像素且不包含_v或_thumb =>在文件擴展名之前將單詞_thumb添加到文件名的末尾。
行了它的所有有關:
if file $picture | grep -q 900x900 && ! file $picture | grep -q _thumb && ! file $picture | grep -q _v;
腳本:
#Change to current .sh directory
cd -P -- "$(dirname -- "$0")"
for picture in */*/Templates/*.jpg
do
filename=${picture##*/}
filename1=$(echo "$filename" |sed 's/.\{4\}$//')
parent_dir="$(dirname -- "$(/usr/local/bin/realpath "$picture")")"
#Colors
red=`tput setaf 1`
green=`tput setaf 2`
magenta=`tput setaf 5`
reset=`tput sgr0`
if file $picture | grep -q 900x900 && ! file $picture | grep -q _thumb && ! file $picture | grep -q _v;
then
mv -v "$picture" "$parent_dir/"$filename1"_thumb.jpg"
echo "${green} [PASS] $filename1 Thumbnail 900x900 found and renamed ${reset}"
else
echo "${magenta} [WARNUNG] $filename1 contains _thumb already or is a _v picture or isn't 900x900 pixels ${reset}"
fi
問題是它不識別圖片,即使它是900x900並且不包含關鍵字。 在此先感謝 –
建議使用http://www.shellcheck.net/...例如,引用您的變量..你可以嘗試'如果文件'$ picture「| grep -q'900x900''沒有其他條件,看看它是否工作? – Sundeep