编写一个脚本。菜单为:
1、创建用户
2、创建目录
3、创建文件
4、修改目录文件
5、修改文件权限
6、删除目录或者文件
7、退出
#!/bin/bash
#write by lijun
#Date 2014-07-15
#======================================================
#function check_error
#======================================================
function ch_error(){
if [ $? -eq 0 ]
then
echo "succeed!"
else
echo "failed...."
fi
}
#=====================================================
#1.function creat_users
#======================================================
function c_users(){
echo "Please input user‘s name"
read name1
useradd $name1
ch_error
echo "return main"
sleep 2
main
}
#======================================================
#2.function creat_directory
#======================================================
function c_dir(){
echo "Please input the path like:[/xx/xx/d_name]"
read path1
mkdir -p $path1
ch_error
echo "return main"
sleep 2
main
}
#=====================================================
#3.function creat_file
#====================================================
function c_file(){
echo "Please input the path like:[/xx/xx/f_name]"
read path2
touch $path2
ch_error
echo "return main"
sleep 2
main
}
#=====================================================
#4.funtion change_directory_name
#=====================================================
function change_dir_name(){
echo "Please input the path like:[/xx/xx/d_name] and the new name **the same path except new name**"
read path3 path4
mv $path3 $path4
ch_error
echo "return main"
sleep 2
main
}
#=====================================================
#5.function chmod_directory
#=====================================================
function chmod_dir(){
echo "Please input the path like:[/xx/xx/d_name] and the permission like:[755]"
read path5 perm
chmod $perm $path3
ch_error
echo "return main"
sleep 2
main
}
#=====================================================
#6.function delete_directory_or_file
#=====================================================
function delete_d_or_f(){
echo "Please input the path like :[xx/xx/directory_name or file_name]"
read path6
rm -rf $path6
ch_error
echo "return main"
sleep 2
main
}
#=============================================================================
main()
{
clear
echo "=============菜单============="
echo " "
echo "1.创建用户"
echo " "
echo "2.创建目录"
echo " "
echo "3.创建文件"
echo " "
echo "4.修改目录文件"
echo " "
echo "5.修改目录权限"
echo " "
echo "6.删除目录或者文件"
echo " "
echo "7.退出"
echo ""
read -p "请输入要选择的功能的序列号(1-7):" a
case $a in
1)
clear
c_users;;
2)
clear
c_dir;;
3)
clear
c_file;;
4)
clear
change_dir_name;;
5)
clear
change_dir;;
6)
clear
delete_d_or_f;;
7)
exit;;
*)
echo "You input the wrong chioce!!";;
esac
}
main
原文地址:http://lj644242741.blog.51cto.com/9245272/1536597