linux下创建目录,高手们帮帮忙
在用户主目录创建一个目录,当输入的目录名存在时,询问用户是否要删除原来的,创建一个新的,
如果输入y就删除了后在创建,否则删除.当输入的目录名不存在时直接创建目录.(用bash实现)
代码如下:
#!/bin/bash
#This program is used to created a directory
echo "Make a Directory"
echo "Please input the name of the directory you want to create:"
read dirname
cd ~
if test -d $dirname
then
echo "the direcoty already exists,delete it y/n"
read yn
if[ "$yn" = "y" ] then
rmdir $dirname
mkdir $dirname
echo "make directory successfully"
exit 1
else
exit 1
fi
else
mkdir $dirname
echo "make directory successfully"
exit 1
fi
结果还是不能创建目录,请高手们帮一下忙?