设为首页 加入收藏

TOP

Linux操作系统基本应用(完结)(六)
2017-10-13 10:27:05 】 浏览:9524
Tags:Linux 操作系统 基本 应用 完结
  图片
    seq 10 产生 1 2 3 。。。。10空格分隔字符串
    [user@bogon ~]$sh xxx.sh  相当于 . / 运行shell文件
————
    for((赋值;条件;运算语句))
    do
    语句
    done; 
    
实例(testfor2.sh):#!/bin/shfor((i=1;i<=10;i++));do
    echo $i;
    done;
     图片
————
    while 条件语句
    do
    语句
    done;
    
    实例1:
    #!/bin/sh
    i=10;
    while [[ $i -gt 5 ]];do
    echo $i;
    ((i--));
    done;
    运行结果:
    ========================
    sh testwhile1.sh
    10
    9
    8
    7
    6
    !!实例2:(循环读取文件内容:)
    #!/bin/sh
    while read line;do
        echo $line;
    done < /etc/hosts;
 
    运行结果:
    ===================
    sh testwhile2.sh

    # Do not remove the following line, or various programs
    # that require network functionality will fail.
    127.0.0.1 centos5 localhost.localdomain localhost
————
    语法结构:
    until 条件
    do
    action
    done
    意思是:直到满足条件,就退出,否则执行action。

    实例
    (testuntil.sh):
    #!/bin/sh
    a=10;
    until [[ $a -lt 0 ]];do
    echo $a;
    ((a--));
    done;
    结果:
    sh testuntil.sh
    10
    9
    8
    7
    6
    5
    4
    3
    2
    1
    0
————
    case选择语句使用(case/esac)
    语法结构
    case $arg in  
        pattern | sample) # arg in pattern or sample  
        ;;  
        pattern1) # arg in pattern1  
        ;;  
        *) #default  
      &
首页 上一页 3 4 5 6 7 8 9 下一页 尾页 6/9/9
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇"fatal: protocol error: ba.. 下一篇【夯实shell基础】shell基础面面观

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目