Shell脚本中判断文件,目录是否存在或者具有权限
来源:互联网 发布:nat网络 编辑:程序博客网 时间:2024/05/02 02:05
shell判断文件,目录是否存在或者具有权限
#!/bin/sh
NovaPath=”/var/log/httpd/”
NovaFile=”/var /log/httpd/access.log”
#这里的-x 参数判断$NovaPath是否存在并且是否具有可执行权限
if [ ! -x "$NovaPath" ]; then
mkdir “$NovaPath”
fi
#这里的-d 参数判断$NovaPath是否存在
if [ ! -d "$NovaPath" ]; then
mkdir “$NovaPath”
fi
#这里的-f参数判断$NovaFile是否存在
if [ ! -f "$NovaFile" ]; then
touch “$NovaFile”
fi
#其他参数还有-n,-n是判断一个变量是否是否有值
if [ ! -n "$NovaVar" ]; then
echo “$NovaVar is empty”
exit 0
fi
#两个变量判断是否相等
if [ "$var1" = "$var2" ]; then
echo ‘$var1 eq $var2′
else
echo ‘$var1 not eq $var2′
fi
大家在写判断语句的时候要特别特别注意空格,楼主被空格快折磨死了:
if[空格 语句 空格]; then XXXXX fi
- Shell脚本中判断文件,目录是否存在或者具有权限
- Shell脚本中判断文件,目录是否存在或者具有权限 (原创)
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- [zz] shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- 二.JavaScript 使用
- ASP.NET MVC 入门3、Routing
- Android中通过反射使用超类的私有属性
- perl中的单引号和双引号
- 架构
- Shell脚本中判断文件,目录是否存在或者具有权限
- C#操作ini文件
- 装饰者模式
- 葵花宝典
- GridView.EmptyDataRowStyle Property
- C#构造蜘蛛爬虫程序
- 【C++】第三章:变量和数据
- 牛
- 【热门主题: 海贼王动漫高清壁纸图集】