#!/bin/sh myPath="/var/log/httpd/" myFile="/var/log/httpd/access.log" #這裏的-x 參數判斷$myPath是否存在而且是否具備可執行權限 if [ ! -x "$myPath"]; then mkdir "$myPath" fi #這裏的-d 參數判斷$myPath是否存在 if [ ! -d "$myPath"]; then mkdir "$myPath" fi #這裏的-f參數判斷$myFile是否存在 if [ ! -f "$myFile" ]; then touch "$myFile" fi #其餘參數還有-n,-n是判斷一個變量是不是否有值 if [ ! -n "$myVar" ]; then echo "$myVar is empty" exit 0 fi #兩個變量判斷是否相等 if [ "$var1" = "$var2" ]; then echo '$var1 eq $var2' else echo '$var1 not eq $var2' fi