#!/bin/bash flag=1 # -e 检测存在性 if [ -e ~/qfedu-linux-advanced-level/day1/test2 ]; then echo "the test dir is exist" else echo "the test dir is not exist" # 等同于 while[ $flag ] # do 用于开始 while 循环 while [ $flag -eq 1 ] do echo "press y to create the dir,press n to exit" read yn case $yn in y) echo "mkdir ~/qfedu-linux-advanced-level/day1/test2" mkdir ~/qfedu-linux-advanced-level/day1/test2 # flag = 0 用于结束 while 循环 flag = 0 # ;; 用于结束 case 语句,相当于 break ;; n) echo "end operation" # exit -1 用于退出脚本,-1 为错误码 exit -1 ;; *) echo "your input is error exit" echo "please input again" flag=1 ;; # esac 用于结束 case 语句 esac # done 用于结束 while 循环 done # fi 用于结束 if 语句 fi cd ~/qfedu-linux-advanced-level/day1/test2 for((i=1 ; i<4 ; i++)) do echo "please input a string, we will create it as a dir" read dir_name if [ -e $dir_name ]; then echo "$i please input other name" else echo "the $dir_name is created" mkdir $dir_name break fi done echo "your times is over" if [ $i -eq 3 ]; then echo "your times is over" exit 0 fi