兄弟连linux一模一样
懒人脚本
[root@localhost ~]# vim sh2006
#!/bin/bash
echo -e "\e[1;31m Can I hlep you ? \e[0m"
echo -e "\e[1;32m \ta --- systemctl restart network \n\tb --- systemctl stop firewalld\n\tc --- ip a\n\td --- shutdown -h now\n\te --- shoutdown -r now\n\tf --- systemclt restart vsftpd\n\tg --- systemctl restart named\n\th --- systemctl restart nmb\n\ti --- systemctl restart smb\n\tj --- systemctl restart httpd \e[0m"
read -t 30 -p "Please you input a-j : " hp
if [ -n "$hp" ]
then
case $hp in
"a")
systemctl restart network
echo "Restart the network card"
/root/sh2006
;;
"b")
systemctl stop firewalld
echo "Turn off the firewall"
/root/sh2006
;;
"c")
ip a
echo "View network card information"
/root/sh2006
;;
"d")
shutdown -h now
echo "Shut down the virtual machine"
/root/sh2006
;;
"e")
shutdown -r now
echo "Restart the virtual machine"
/root/sh2006
;;
"f")
systemctl restart vsftpd
echo "Restart the ftp"
/root/sh2006
;;
"g")
systemctl restart named
echo "Restart the DNS"
/root/sh2006
;;
"h")
systemctl restart nmb
echo "Restart the nmb"
/root/sh2006
;;
"i")
systemctl restart smb
echo "Restart the nmb"
/root/sh2006
;;
"j")
systemctl restart httpd
echo "Restart the http"
/root/sh2006
;;
"l")
echo "exit"
;;
*)
echo "No such option"
;;
esac
fi
[root@localhost ~]# chmod 755 /root/sh2006 [root@localhost ~]# ./sh2006

#!/bin/bash
#输出列表,1,2,3
echo "上苙丞 ,please :1"
echo "八星联 ,please :2"
echo "掟上今日子,please:3"
#读取dec这个变量
read -t 30 -p "input you like detective,please:" dec
#多分支case语句选择输入出
case "$dec" in
"1")
echo "you choice 上苙丞."
;;
"2")
echo "you choice 八星联."
;;
"3")
echo "you choice 掟上今日子."
;;
*)
echo "input right informaition,please!"
;;
esac
~
shell多分支case语句
case $变量名 in
"值1")
code1
;;
"值2"
code2
;;
*)
code
;;
esac
#! /bin/bash
read -t 30 -p "please input yes or no" cho
cash $cho in
"yes")
echo "you choose is yes"
;;
"no")
echo "you choose is no"
;;
*)
echo "your choose is error"
;;
esac
多分支case条件语句
case语句和if...elif...else语句一样都是多分支条件语句,不过和if多分支条件语句不同的是,case语句只能判断一种条件关系,而if语句可以判断多种条件关系。
case $变量名 in
"值1")
如果变量的值等于值1,则执行程序1
;;
"值2")
如果变量的值等于值2,则执行程序2
;;
…省略其他分支.…
*)
如果变量的值都不是以上的值,则执行此程序
;;
esac
vi case.sh
#!/bin/bash
read -t 30 -p "please input yes/no:" cho
case "$cho" in
"yes")
echo "yes"
;;
"no")
echo "no"
;;
*)
echo "please input yes/no again!!!"
;;
esac
#!/bin/bash
read -t 10 -p "please input your choice yes/no: " choice
case $choice in
"yes")
echo "your choice is yes"
;;
"no")
echo "your choice is no"
;;
*)
echo "your choice is another"
;;
esac
case语句
多分支语句case语句
case语句
case 示例
case 判断语法
多分支case语句
多分支case语句