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