天天看點

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,如需轉載請自行聯系原作者