zoukankan      html  css  js  c++  java
  • Shell计算器

    #!/bin/bash
    # filename : jisuan.sh
    # description : add, subtract, multiply, and divide
    print_usage(){
    echo -e "USAGE:$0 NUM1 {+|-|*|%} NUM2"
    exit 1
    }
    if [ $# -ne 3 ];then
    print_usage
    fi

    firstnum=$1
    secondnum=$3
    op=$2

    if [ -n "$(echo $firstnum|sed 's/[0-9]//g')" ];then
    print_usage
    fi

    if [ "$op" != "+" ]&&[ "$op!="-"" ]&&[ "$op" != "*" ]&&[ "$op" != "/" ];then
    print_usage
    fi

    if [ -n "$(echo $secondnum|sed 's/[0-9]//g')" ];then
    print_usage
    fi

    echo "${firstnum}${op}${secondnum}=$((${firstnum}${op}${secondnum}))"

    另;echo $(($1))

  • 相关阅读:
    JQuery_1
    CSS_1
    CSS_3
    CSS_4
    2020.10.19小记
    CSS_2
    IT茧
    亲爱的小C
    四五点钟的太阳
    有聊
  • 原文地址:https://www.cnblogs.com/shengy/p/7427105.html
Copyright © 2011-2022 走看看