结合一些简单的LINUX命令编写一个脚本实现简单的菜单功能,掌握IFwhile,for等条件和循环语句使用
1个回答
2013-09-12
展开全部
供参考:(一),实现菜单操作;
(二),实现新增用户,删除用户,修改用户名,修改用户密码。
while :
do
cat << EOF
================================================================= Welcome to use the shellscripts 1.Add user
2.Delete user
3.Modify username
4.Modify password
q.Quit=================================================================
EOF read -p "Please enter your choice: " CHOICE
case $CHOICE in
1) read -p "Please enter username: " USERNAME
useradd $USERNAME && echo "User create ok!"
;;
2) read -p "Please enter username: " USERNAME
userdel -r $USERNAME && echo "User delete ok"
;;
3)
read -p "Please enter oldusername: " USERNAME1 read -p "Please enter newusername: " USERNAME2
usermod -l $USERNAME2 $USERNAME1 && echo "Username modify ok"
;;
4)
read -p "Please enter username: " USERNAME
passwd $USERNAME
;;
q|Q)
clear
exit 0
;;
*)
clear
;;
esac
done
(二),实现新增用户,删除用户,修改用户名,修改用户密码。
while :
do
cat << EOF
================================================================= Welcome to use the shellscripts 1.Add user
2.Delete user
3.Modify username
4.Modify password
q.Quit=================================================================
EOF read -p "Please enter your choice: " CHOICE
case $CHOICE in
1) read -p "Please enter username: " USERNAME
useradd $USERNAME && echo "User create ok!"
;;
2) read -p "Please enter username: " USERNAME
userdel -r $USERNAME && echo "User delete ok"
;;
3)
read -p "Please enter oldusername: " USERNAME1 read -p "Please enter newusername: " USERNAME2
usermod -l $USERNAME2 $USERNAME1 && echo "Username modify ok"
;;
4)
read -p "Please enter username: " USERNAME
passwd $USERNAME
;;
q|Q)
clear
exit 0
;;
*)
clear
;;
esac
done
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询