shell 判断文件和路径
时间:2014-10-16 12:36:02
收藏:0
阅读:156
#!/bin/sh
filePath="/Users/xxx"
fileName="/Users/xxx/xxx"
#这里的-x 参数判断$myPath是否存在并且是否具有可执行权限
if [ ! -x "$filePath"]; then
mkdir "$filePath"
fi
#这里的-d 参数判断$myPath是否存在
if [ ! -d "$filePath"]; then
mkdir "$filePath"
fi
#这里的-f参数判断$myFile是否存在
if [ ! -f "$fileName" ]; then
touch "$fileName"
fi
#其他参数还有-n,-n是判断一个变量是否是否有值
if [ ! -n "$myVar" ]; then
echo "$myVar is empty"
exit 0
fi
[@more @]
评论(0)