wangyan188 发表于 2018-8-27 08:30:02

shell脚本练习(12.10)

  任意三个数,判断最大数
  思路:1.先要输出三个数字
  2.假设第一个数字是最大数
  3.用第二个数字和第一个数字对比,如果第二个数字大最大值就变成第二个数字
  4.用第三个数字和第一个数字对比,如果第三个数字大最大值就变成第三个数字
  5.输出最大的数字
  vim duibi.sh
  #!/bin/bash
  #written by lizheng
  #about duibi
  echo "please enter three number:"
  read -p "the first number is:" n1
  read -p "the second number is:" n2
  read -p "the third number is:" n3
  let max=$n1
  if [ $n2 -ge $n2 ] ;then
  max=$n2
  fi
  if [ $n3 -ge $n1 ] ;then
  max=$n3
  fi
  echo "the max number is $max."


页: [1]
查看完整版本: shell脚本练习(12.10)