zoukankan      html  css  js  c++  java
  • #每日Linux小练习#08 Shell Script知识点总结(下)

    今天对Script中的循环进行练习,然后使用一些script的调试参数

    while

    #while
    while [ "$yn" != "yes" -a "$yn" != "YES" ]
    do
        read -p "Please input YES/yes to stop this program:" yn
    done
    echo "OK! you input the correct answer"

    until

    #until
    until [ "$yn" == "no" -o "$yn" == "NO" ]
    do 
        read -p "Please input no/NO to stop this program:" yn
    done
    echo "OK! you input the correct answer"

    for

    #for
    function printAnimal() {
        for animal in $@
        do
            echo "$animal"
        done 
    }
    printAnimal cat dog elephant
    
    user=$(cut -d ':' -f1 /etc/passwd)
    for username in $user
    do
        echo "$username"
    done
    
    s=0
    nu=12
    for(( i=1; i<=$nu ; i=i+1))
    do
        s=$(($s + $i))
    done
    echo "The result of '1+2+3+...+12' is ==> $s"

    script调试

    sh -x 20150810loop.sh

    可以看到完整的执行过程,比如上文代码中的最后一个循环

  • 相关阅读:
    java坏境内存不够用 大量占用swap 临时加swap
    磁盘分区
    简述raid0,raid1,raid5,raid10 的工作原理及特点
    给用户提权
    用户的环境变量被删除了
    定时任务
    linux权限
    kafka部署
    数据仓库
    kylin
  • 原文地址:https://www.cnblogs.com/wuqi/p/4724038.html
Copyright © 2011-2022 走看看