shell判断文件是否存在(模板)的一段代码
时间:2014-09-10 21:43 来源:linux.it.net.cn 作者:it
使用shell进行判断一个文件是否存在,如果不存在则创建它。
复制代码代码如下:
#!/bin/bash
proclock(){
if [ -e $1 ];then
echo "this file is exist.."
else
echo "this file is not exist,but while be touch.."
touch $1
fi
}
read -p "please input the filename: "
DIR=`dirname $REPLY`
[ ! -d $DIR ] && mkdir -p $DIR
proclock $REPLY
(责任编辑:IT)
使用shell进行判断一个文件是否存在,如果不存在则创建它。
复制代码代码如下:
#!/bin/bash
read -p "please input the filename: " (责任编辑:IT) |