1.判斷文件夾及文件是否存在,不存在則創建 (https://www.jb51.net/article/34330.htm)
注意:在if和[]之間以及[ ]和之中內容之間都要有空格,否則會出現錯誤[: missing `]'(https://blog.csdn.net/u_ranfa/article/details/84638063)
logPath="/export/Logs/xxx/" logFile="/export/Logs/xxx/xxx.log" # 這裏的-x 參數判斷$logPath是否存在並且是否具有可執行權限 if [ ! -x "$logPath" ]; then mkdir "$logPath" fi # 這裏的-f參數判斷$logFile是否存在 if [ ! -f "$logFile" ]; then touch "$logFile" fi