一、语法

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:~$

相关文章:

  • 2022-01-01
  • 2021-12-06
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
  • 2021-07-02
  • 2021-12-10
猜你喜欢
  • 2021-07-22
  • 2021-12-06
  • 2021-12-30
  • 2021-06-21
  • 2021-12-14
  • 2022-02-08
  • 2021-07-06
相关资源
相似解决方案