#!/bin/bash
cd ~
dir="test"
if [ -d "$dir" ];then
num=0
while (($num < 3));do
read -p "Input file name:" file
if [ -f "$dir/$file" ];then
echo "file is exists,please input other file name"
num=`expr $num + 1`
continue
else
touch $dir/$file
break
fi
done
else
read -p "test dir is not exists, are you want to create it?[y/n]" ch
if [ "$ch" = "y" ];then
mkdir -p $dir
else
exit 1
fi
fi
温馨提示:答案为网友推荐,仅供参考