#!/bin/sh
#使用变量(等号两边不能有空格)
#var="hello"
#echo "$var"
#for 遍历有file(注意当前路径)("$fileList" 和 $fileList 是有区别的,前者是用字符串包含了所有的路径)
#fileList=`find . -name '*.tga'`
#for file in $fileList
#do
#echo $file
#done
:<<!
#if 语句的使用 (要在中括号[ ]中的条件两侧加上空格)
fileList=`find . -name '*.tga'`
for file in $fileList
do
fileW=`identify -format "%w" $file`
fileH=`identify -format "%h" $file`
if [ $fileW == $fileH ]
then
echo "$fileW" "$fileH"
echo "$file"
fi
done
!
注意的地方:
1. 因为上面的.sh文件是在Window编写的,想要.sh文件在CygWin可以正常运行,那么换行符要转为 UNIX 的 LF。
2. 在使用变量的时候,等号两边不能有空格。
3. fileList=`find . -name '*.tga'`
3.1 for file in $fileList
3.2 for file in "$fileList"
3.1 和 3.2 的写法是有区别的,
3.1 是1个1个路径进行遍历,for 循环是多次的,而3.2 "$fileList" 这种写法就是把所有find出来的路径都塞到一个字符串中,for循环就只有1次。
4 在写if 语句的时候,[] 条件两侧加上空格