「Shell」Shell 脚本学习──文件存在判断
2012-04-13 08:38
519 查看
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
来自: http://hi.baidu.com/sshow224/blog/item/c6ce75c35d3fde5cb219a875.html
#!/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
来自: http://hi.baidu.com/sshow224/blog/item/c6ce75c35d3fde5cb219a875.html
相关文章推荐
- Shell 脚本学习──文件存在判断
- 判断文件是否存在的shell脚本代码
- shell 脚本判断文件是否存在
- 判断文件是否存在的shell脚本代码
- 如何在shell脚本中判断文件或者文件夹是否存在?
- Shell脚本中判断文件,目录是否存在或者具有权限
- shell脚本判断文件是否存在
- 如何在shell脚本中判断文件或者文件夹是否存在?
- shell 脚本判断某个文件是否存在
- 如何在shell脚本中判断文件或者文件夹是否存在?
- shell脚本学习(3)文件判断
- Shell脚本中,判断Hadoop文件是否存在
- 判断文件是否存在的shell脚本代码
- shell 脚本判断文件、文件夹是否存在
- shell脚本中判断文件是否存在
- Shell脚本中判断文件,目录是否存在或者具有权限 (原创)
- 判断文件是否存在的shell脚本代码
- 判断文件是否存在的shell脚本代码
- Shell脚本执行hive语句 | hive以日期建立分区表 | linux schedule程序 | sed替换文件字符串 | shell判断hdfs文件目录是否存在
- 判断文件是否存在的shell脚本代码