测试目录创建结果一个脚本
时间:2006-02-18 来源:lichuanhua
测试目录创建结果一个小脚本
#!/bin/sh
#ifmkdir DIRECTORY=$1
#如果没有此目录,提示创建目录
if [ "$DIRECTORY" = "" ]
then
echo "Usage :`basename $0` directory to create" >&2
exit 1
fi
#如果有相同的文件名存在,提示有相同文件名存在
if [ -f $DIRECTORY ]
then
echo "Usage:`basename $0`,Has had the same file name exists"
exit 1
fi
if [ -d $DIRECTORY ]
then :
else
echo "The directory does exist"
echo -n "Create it now? [y..n] :"
read ANS
if [ "$ANS" = "y" ] || [ "$ANS" = "Y" ]
then
echo "creating now"
mkdir $DIRECTORY >/dev/null 2>&1
#如果mkdir创建目录的失败,则提示创建目录出错
if [ $? != 0 ]
then
echo "errors creating the directory" >&2
exit 1 fi
elif [ "$ANS" = "N" ] || [ "$ANS" = "n" ]
then
echo "You select not create"
else
echo "please enter \"y\" or \"n\" "
fi
fi
#ifmkdir DIRECTORY=$1
#如果没有此目录,提示创建目录
if [ "$DIRECTORY" = "" ]
then
echo "Usage :`basename $0` directory to create" >&2
exit 1
fi
#如果有相同的文件名存在,提示有相同文件名存在
if [ -f $DIRECTORY ]
then
echo "Usage:`basename $0`,Has had the same file name exists"
exit 1
fi
if [ -d $DIRECTORY ]
then :
else
echo "The directory does exist"
echo -n "Create it now? [y..n] :"
read ANS
if [ "$ANS" = "y" ] || [ "$ANS" = "Y" ]
then
echo "creating now"
mkdir $DIRECTORY >/dev/null 2>&1
#如果mkdir创建目录的失败,则提示创建目录出错
if [ $? != 0 ]
then
echo "errors creating the directory" >&2
exit 1 fi
elif [ "$ANS" = "N" ] || [ "$ANS" = "n" ]
then
echo "You select not create"
else
echo "please enter \"y\" or \"n\" "
fi
fi
相关阅读 更多 +