Exercise 1 shell script to create directories and files

Enter a directory to determine whether there is, if there is no prompt is given, if you are prompted to enter the name of the file to be created, whether it's the file created by the presence, if not, continue to create, change or prompt file already exists, with function implementation
# bin / bash
CreateFile () {
cd $ 1
the Read -p "Please enter the file name" filename
IF [-f "$ filename"]
the then
echo "file already exists"
the else
echo "began to create the file"
Touch $ filename
echo " created "
fi
}


read -p "Please enter a directory" dir
IF [-d "$ dir"]
the then
CreateFile $ dir
the else
echo "directory does not exist"
fi

Guess you like

Origin www.cnblogs.com/zhaobobo10/p/12148431.html