1、编写menu.sh脚本
#!/bin/bash # function menu(){ cat << EOF `echo -e "\033[30;47m########################################\033[0m"` `echo -e "\033[32mMy Menu\033[0m"` `echo -e "\033[30;47m########################################\033[0m"` * `echo -e "\033[35m1)add a user\033[0m"` * `echo -e "\033[35m2)delete a user\033[0m"` * `echo -e "\033[35m3)quit\033[0m"` * `echo -e "\033[35m4)return main menu\033[0m"` EOF }
2、编写adminuser.sh脚本#!/bin/bash
# clear . menu.sh menu while true;do read -p "please inoput a option: " option case $option in 1) read -p "add a user: " name read -p "set passwd for the user: " pass useradd $name &>/dev/null if [ $? -eq 0 ];then echo -e "\033[32;40m$name is created succesufully!!!\033[0m" echo $pass | passwd --stdin $name &>/dev/null else echo -e "\033[32;40muser $name is created failly!!!\033[0m" fi ;; 2) read -p "delete a user: " name userdel -r $name &>/dev/null if [ $? -eq 0 ];then echo -e "\033[32;40m$name is deleted successfully!!!\033[0m" else echo -e "\033[32;40m$name is deleted failly!!!\033[0m" fi ;; 3) echo -e "\033[32;40mquit successfully!!!\033[0m" break ;; 4) clear menu ;; esac done
3、测试脚本
#./adminuser.sh