我需要检查图像是否有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