首页 > 系统服务 > 详细

case做带选项的shell脚本以及结合while做交互选择的shell脚本的最基本写法

时间:2015-11-18 10:46:16      阅读:312      评论:0      收藏:0      [点我收藏+]

1、case做带选项的执行脚本:

#!/bin/bash

case $1 in

x)

echo "x is selected"

;;

*)

echo "please use x"

esac


二、case结合while做交互脚本:

#!/bin/bash

while true

do

read -p "Enter port of chaoxingdata(d,1): " port

case ${port} in

d)

echo "port=${port}"

read -p "press enter to continue"

;;

1)

echo "port=${port}"

read -p "press enter to continue"

;;

*)

echo "error input,you fool"

read -p ‘type "go" to continue: ‘ go

if [ ! ${go} = go ] || [ -z ${go} ]

then

exit

fi

esac

done

case做带选项的shell脚本以及结合while做交互选择的shell脚本的最基本写法

原文:http://zhukeqiang.blog.51cto.com/8692790/1713891

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!