您的位置:首页 > 运维架构 > Shell

shell-判断一个目录是否存在,不存在是否创建

2016-06-03 09:39 786 查看
#!/bin/bash
is_it_a_directory()#用于判断一个目录是否存在
{
if [ $# -lt 1 ]
then
echo "is_it_a_directory:I need an argument"
return 1
fi
_DIRECTORY_NAME=$1
if [ ! -d $_DIRECTORY_NAME ]
then
return 1
else
return 0
fi

}
#是否创建
echo "enter destination directory:"
read DIREC
if is_it_directory $DIREC >/dev/null 2>&1
then :
else
echo "$DIREC does not exits, create it now?[y..n]"
read choice
if [ "$choice" = "y" ]
then
mkdir $DIREC
echo "create $DIREC ok"
else
echo "see you again"
fi
fi
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: