shellScript之util语句

来源:互联网 发布:淘宝上的dota2 编辑:程序博客网 时间:2024/06/05 03:36
#!/bin/bashi=0until [[ "$i" -gt 5 ]]do    let "square=i*i"    echo "$i * $i = $square"    let "i++"done

结果:

~/Note/test # ./15until.sh 0 * 0 = 01 * 1 = 12 * 2 = 43 * 3 = 94 * 4 = 165 * 5 = 25

例子2:

#!/bin/bashecho "Please input the num(1-10):"read numuntil [[ "$num" = 4 ]]do    if [ "$num" -lt 4 ];thenecho "Too small,Try again:"read num    elif [ "$num" -gt 4 ];thenecho "To high,Try again:"read num    elseexit 12    fidoneecho "congralutional,you got it."       

结果:

~/Note/test # ./16until.sh Please input the num(1-10):5To high,Try again:3Too small,Try again:4congralutional,you got it.


原创粉丝点击