zoukankan      html  css  js  c++  java
  • bash中的算术运算

    bash中的算术运算
        +, -, *, /, %
        实现算术运算:
            (1) let var=算术表达式
             (2) var=$[算术表达式]
             (3) var=$((算术表达式))
           
            let aa=1+2
            或者aa=$[1+2]
            或者aa=$((1+2))
            echo aa
                输出为3
            aa=$[$aa+3]
            echo aa
                输出为6
       
    bash中的增强型赋值:
            +=, -=, *=, /=, %=

            aa+=2   --->   aa=$[$aa+2]
            aa-=3   --->   aa=$[$aa-3]

            let var++   let aa++  --->   let  aa=$aa+1
            let var--   let aa--  --->   let  aa=$aa-1


        练习:写一个脚本
            计算/etc/rc.d/rc.sysinit的行数与/etc/rc.d/init.d/fucntions文件行数之和;
                #!/bin/bash
                syslines=`wc -l /etc/rc.d/rc.sysinit |cut -d " " -f 1`
                funclines=$(wc -l /etc/rc.d/init.d/functions |cut -d " " -f 1)
                lines=$[$syslines+$funclines]
                lines=$((lines=$[$syslines+$funclines]))
                let lines=$syslines+$funclines           
                echo $lines

  • 相关阅读:
    HTML5结构
    HTML5新增的非主体元素header元素、footer元素、hgroup元素、adress元素
    CF GYM 100703G Game of numbers
    CF GYM 100703I Endeavor for perfection
    CF GYM 100703K Word order
    CF GYM 100703L Many questions
    CF GYM 100703M It's complicate
    HDU 5313 Bipartite Graph
    CF 560e Gerald and Giant Chess
    POJ 2479 Maximum sum
  • 原文地址:https://www.cnblogs.com/yajing-zh/p/4878308.html
Copyright © 2011-2022 走看看