read 命令

语法格式: read [参数] [变量名]

常用参数如下:

-p prompt: 提示信息

-t timeout: 等待时间,单文秒

 

#!/bin/sbin

read -p "please input your choice:" choice

case "$choice" in
    1)
        echo "The num you input is 1"
        ;;
    2)
        echo "The num you input is 2"
        ;;
    [3-9])
        echo "The num you input is $choice"
        ;;
    *)
        echo "Please input [0-9] int"
        exit
esac

 

同时接收两个变量

read -p "Please input two number:" var1 var2
if [ $# -ne 2 ];then
        echo "please input two number!"
        exit
fi
echo $[var1+var2]

 

posted @ 2017-03-14 15:02  Vincen_shen  阅读(157)  评论(0编辑  收藏  举报