美文网首页
shell循环

shell循环

作者: 蓝色科学史 | 来源:发表于2019-11-29 10:27 被阅读0次
    #!/bin/bash 
    # c style
    for((i=1;i<=10;i++));  
    do   
    echo $(expr $i \* 3 + 1);  
    done 
    
    # shell style
    for i in $(seq 1 10)  
    do   
    echo $(expr $i \* 3 + 1);  
    done  
    
    # math style
    for i in {1..10}  
    do  
    echo $(expr $i \* 3 + 1);  
    done 
    
    # basic style
    awk 'BEGIN{for(i=1; i<=10; i++) print i}'  
    
    # string loop
    for i in `ls`;  
    do   
    echo $i is file name;  
    done
    
    for i in $* ;  
    do  
    echo $i is input chart;  
    done  
    
    for i in f1 f2 f3 ;  
    do  
    echo $i is appoint;  
    done  
    
    list="rootfs usr data data2"  
    for i in $list;  
    do  
    echo $i is appoint;  
    done 
    
    # path loop
    for file in /proc/*;  
    do  
    echo $file is file path;  
    done 
    
    for file in $(ls *.sh)  
    do  
    echo $file is file path;  
    done 
    

    相关文章

      网友评论

          本文标题:shell循环

          本文链接:https://www.haomeiwen.com/subject/qtuwwctx.html