Shell 编程基础之 Until 练习

一、语法

until [ condition ]  # 和while相反,当 condition 条件成立时,就终止回圈, 否则就持续进行回圈的程序段
do
    #执行内容
done

二、练习

  1. 输入用户输入的参数,直到用户输入 "end" 结束循环
    until
    read -p "Plz input a paramter": param
    test $param = "end"
    do
    echo "$param"
    done
    user@ae01:~$ ./test.sh
    Plz input a paramter:a
    a
    Plz input a paramter:b
    b
    Plz input a paramter:c
    c
    Plz input a paramter:end
    user@ae01:~$
  2. 输出1到5的自然数
    i=1
    until [ "$i" -gt 5 ]
    do
    echo "$i"
    i=$(($i+1))
    done
    user@ae01:~$ ./test.sh
    1
    2
    3
    4
    5
    user@ae01:~$
原文地址:https://www.cnblogs.com/tannerBG/p/4057034.html