【shell】Linux shell 之 case 详解
发布时间:2020-12-15 19:39:23 所属栏目:安全 来源:网络整理
导读:总的来说,case是一个判断语句 ,比if更加容易理解一点。 case 语句格式 case in 变量 值1) 内容 ;;值2) 内容 ;;esac 注意:每个内容后面都需要添加 ;; ,可以跨行也可以同行写。 实例:根据用户输入的选择执行语句。 #!/bin/bash -# 打印选择菜单cat EOF Op
case in 变量 值1) 内容 ;; 值2) 内容 ;; esac 注意:每个内容后面都需要添加 ;; ,可以跨行也可以同行写。
#!/bin/bash - # 打印选择菜单 cat <<EOF Option: 1) restart networking service. 2) start networking service. 3) stop networking service. *) exit. EOF read -p "Please enter a option:" number # 使用case语句对参数进行判断 case $number in 1) echo "The Networking service is restart,wait......" ;; 2) echo "The Networking service is start,wait......" ;; 3) echo "The Networking service is stop,wait......" ;; *) echo "exit." ;; esac [root@XiaoPeng scripts]# bash case.sh 版权所有:arppinging (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |