1、第一部分If的用法第一种 if list then do something here fi 当list表述返回值为True(0)时,将会执行"do something here"。#!/bin/shmyPath="/var/log/httpd/"myFile="/var/log/httpd/access.log"1.是否存在并且是否具有可执行权限#这里的-x参数判断$myPathif[!-x"$myPath"];thenmkdir"$myPath"fi2.目录是否存在#这里的-d参数判断$myPath是否存在if[!-d"$myPath"];thenmkdir"$myPa
2、th"fi3.文件是否存在#这里的-f参数判断$myFile是否存在if[!-f"$myFile"];thentouch"$myFile"fi1.变量是否有值#其他参数还有-n,-n是判断一个变量是否是否有值if[!-n"$myVar"];thenecho"$myVarisempty"exit0fi2.两个变量判断是否相等if["$var1"="$var2"];thenecho'$var1eq$var2'elseecho'$var1noteq$var2'fi3.比较数字的大小if[$df-gt50] then $df>diskalert else exitfi4.字符串