shell脚本条件语句和循环语句示例

    技术2025-05-13  10

    条件语句为真,用冒号表示

    循环条件为真,用冒号表示

    当然,也可参考C语言的写法,条件 写true

    例1:while语句

    #!/bin/sh while : do echo "hello" sleep 1 done #!/bin/sh while true do echo "hello" sleep 1 done

     

    如上所示,使用:  或者 true  都是可以的。 

    例2:if语句

    #!/bin/sh if : then echo "hello" sleep 1 fi #!/bin/sh if true then echo "hello" sleep 1 fi

     

    if语句如图,二者效果等同 

    Processed: 0.009, SQL: 9