天天看点

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

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

#!/bin/bash

case $1 in

x)

echo "x is selected"

;;

*)

echo "please use x"

esac

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

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 "error input,you fool"

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

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

then

exit

fi

done

本文转自 朱科强 51CTO博客,原文链接:http://blog.51cto.com/zhukeqiang/1713891,如需转载请自行联系原作者