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

来源:互联网 发布:nba关注软件 编辑:程序博客网 时间:2024/04/29 04:01
#!/bin/bashis_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 DIRECif is_it_directory $DIREC >/dev/null 2>&1then :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"    fifi
2 0
原创粉丝点击