shell 编程语法总结(I/O 逻辑控制结构)

6 篇文章 0 订阅
FIRST:control structure
     1 CONDITION--if
         The Form:  
        if [ expression ]
            then
                command
        elif [ expression ] 
            then
                command
        ....
        else
                command
        fi 
    For example:
        if [ $# -lt 2 ] 
            then
                echo "Error!Arguments are not enough!"
        elif [ $# -gt 2 ]
            then
                echo "Error!Arguments are too many!"
        else
                echo "Good!U are great!"            
        fi
    Summary:
    (1)operator         meaning
        -eq                  equal to
        -ne                  not equal to
        -lt                    less than
        -le                    less than or equal
        -gt                   great than
        -ge                   great than or equal
    (2)there must be ' ' space at the two side of '[' and ']'

    (3)"if" and "fi" are a pair

    (4)if [ expression ] ;then
        or
        if [ expression ] 
                then
        these two forms are all right!
     2CONDITION--case
         The Form:              
            case word in

                   pattern1 )
                        command-list1
                        ;;
                   pattern2 )
                        command--list2
                         ;;
                   ...
            
esac
         Summary :
            (1)";;" or ";&" or ";;&"
                ";;" carry out the command-list will exit the case structure
                ";&" and ";;&"carry out the command-list will continue matching the next pattern
            (2)
                "case" and "esac" are a pair
            (3)
                the pipe can be used in pattern,for example
                    a|b|c|...)
                        command-list
                        ;; 
    3CIRCULATE--while
        The Form:
            while [ expression ] 
                do
                    command
                done

            or
           while [ expression ] ; do command ; done
    

SECOND:I/O and pipe
    1 OUTPUT
        redirection output operator
            '>' only output the content to the place and the next '>' will cover the content in it.
            '>>' add the output contnet to the place at the end. That is to say it will not cover the content in it .

        the default output is 1; the error information output is 2
        so "1> a" can redirect the standard output to a
             "2> b" can redirection the error output to b
            "&> a" and "1>a 2>&1" and "2>a 1>&2" can output the all content to a
        The Form:
            command > a
            {command1; command2; command3; ...} > a 
            command >> a
            command 1> a 2> b

    2INPUT:
        The Form:
            command < filename


THIRD:quote
1(\)
    Form:
        \(character)
    For example:       
        echo Price:\$2
        then putout: Price:$2
            but not putout the second parameter
2('' )
    Form:
        'character string'
    For example:
        echo 'The book <
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(9) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值