zoukankan      html  css  js  c++  java
  • 053-比较输入任意两个数字大小

    题目:任意输入两个整数,比较他们的大小

    [root@cnsz142728 scripts]# vim pupu.sh
    #!/bin/bash
    a=$1
    b=$2
    if [ $# -ne 2 ];then
       echo "USAGE:$0 arg1 arg2"
       exit 2
    fi
    
    expr $a + 1 &>/dev/null
    start=$?
    expr $b + 1 &>/dev/null
    start1=$?
    if [ $start -ne 0 -a $start1 -ne 0 ]; then
      echo "Please input two again"
      exit 33
    fi
    if [ $a -eq $b ];then
      echo "$a=$b"
    elif [ $a -lt $b ];then
      echo "$a<$b"
    elif [ $a -gt $b ];then
      echo "$a>$b"
    fi
    ~
    "pupu.sh" [New] 23L, 357C written                             
    [root@cnsz142728 scripts]# chmod +x pupu.sh 
    [root@cnsz142728 scripts]# ./pupu.sh 
    USAGE:./pupu.sh arg1 arg2
    [root@cnsz142728 scripts]# ./pupu.sh 3 3
    ./pupu.sh: line 13: [: -a: integer expression expected
    3=3
    [root@cnsz142728 scripts]# ./pupu.sh 3 4
    ./pupu.sh: line 13: [: -a: integer expression expected
    3<4
    [root@cnsz142728 scripts]# ./pupu.sh 3 1
    ./pupu.sh: line 13: [: -a: integer expression expected
    3>1
    [root@cnsz142728 scripts]# ./pupu.sh 2.2 2.2
    Please input two again
    
    

    转载于:https://my.oschina.net/u/3635512/blog/1543614

  • 相关阅读:
    网络之传输层
    局域网的物理组成
    网络基础
    RAID磁盘阵列
    mount挂载和交换分区swap
    Linux文件系统
    sed命令基础2
    sed命令基础
    LVM基础
    磁盘配额基础
  • 原文地址:https://www.cnblogs.com/twodog/p/12139313.html
Copyright © 2011-2022 走看看