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
相关文章推荐
- shell代码段1
- Powershell学习之道-文件夹共享及磁盘映射
- makefile之嵌套shell命令
- 初识shell
- bash命令/文件管理-文件管理
- bash命令/文件管理-vim操作
- bash命令/文件管理-基本命令
- bash命令/文件管理-bash命令
- shell脚本输出1-1000内的偶数
- Linux操作系统基础解析之(七)——Bash(Shell)基础知识(2)
- shell脚本的时间指令date
- shell 实现N位自动补零和日期循环
- adb shell input swipe 1000 100 0 0
- shell字符段截取
- 【SHELL】批量下载GIT代码
- Linux-shell脚本-for语句/where语句/until语句
- Linux-shell脚本-if语句/case语句
- Powershell学习之道-文件夹共享及磁盘映射
- 检查mysql是否成功启动的方法(bat+bash)
- Shell脚本8种字符串截取方法总结