zoukankan      html  css  js  c++  java
  • WindowsBatch与LinuxShell比较[shell循环实例]


    Shell的循环实例:


    #!/bin/bash
    for i in 1 2 3 4 5
    do
       
    echo "Welcome $i times"
    done

    #!/bin/bash
    for i in $(seq 1 1 5)
    do
       
    echo "Welcome $i times"
    done

    #!/bin/bash
    for i in {1..5}
    do
       
    echo "Welcome $i times"
    done

    #!/bin/bash
    for (( c=1; c<=5; c++ ))
    do
        
    echo "Welcome $c times"
    done


    #!/bin/bash
    for i in $( ls ); do
       
    echo item: $i
    done



    #!/bin/bash
    for i in `seq 1 10`;
      
    do
        
    echo $i
    done    

    #!/bin/bash
    for file in /etc/*
    do
        
    if [ "${file}" == "/etc/resolv.conf" ]
        
    then
            countNameservers
    =$(grep -c nameserver /etc/resolv.conf)
            
    echo "Total  ${countNameservers} nameservers defined in ${file}"
            
    break
        fi
    done

    #!/bin/bash
    FILES="$@"
    for f in $FILES
    do
            
    # if .bak backup file exists, read next file
        
    if [ -f ${f}.bak ]
        
    then
            
    echo "Skiping $f file"
            continue  
    # read next file and skip cp command
        fi
            
    # we are hear means no backup file exists, just use cp command to copy file
        
    /bin/cp $$f.bak
    done


    #!/bin/bash 
    COUNTER
    =0
    while [  
    $COUNTER -lt 10 ]; do
        
    echo The counter is $COUNTER
        let COUNTER
    =COUNTER+1 
    done



    #!/bin/bash 
    COUNTER
    =20
    until [  
    $COUNTER -lt 10 ]; do
        
    echo COUNTER $COUNTER
        let COUNTER-
    =1
    done

    完!

    作者:iTech
    微信公众号: cicdops
    出处:http://itech.cnblogs.com/
    github:https://github.com/cicdops/cicdops

  • 相关阅读:
    第1章:程序设计和C语言(C语言入门)
    倒计时IE6+
    uploadify 使用 详细 说明
    HTTP&#160;错误
    asp.net 向后台提交 html 代码段 包括 <> 标签
    C#使用NLog记录日志
    IE浏览器 location.href 不跳转
    .Net Core 导出Excel
    .net mvc 获取acion 返回类型
    sql sever 执行较大的文件脚本
  • 原文地址:https://www.cnblogs.com/itech/p/1574025.html
Copyright © 2011-2022 走看看