shell作业1

  1. 编写函数,实现打印绿色OK和红色FAILED
    判断是否有参数,存在为Ok,不存在为FAILED
args(){
  if [ $1 -ge 1 ]
  then
    echo -e "\033[32m OK \033[0m"
  else
    echo -e "\033[31m FAILED \033[0m"
  fi
}

args $#
  1. 编写函数,实现判断是否无位置参数,如无参数,提示错误
args(){
#  if [ "$*" == "" ]
  if [ -z "$*" ] 
  then
    echo "no args"
  fi
}
args $*
  1. 编写函数实现两个数字做为参数,返回最大值
max1() {
  expr $1 + 1 &> /dev/null;[ $? -eq 2 ] && { echo "$1 isn't num";return 1;}
  expr $2 + 1 &> /dev/null;[ $? -eq 2 ] && { echo "$2 isn't num";return 1;}

  if [ $1 -ge $2 ]
  then
    echo "$1 is max"
    break
  else
    echo "$2 is max"
    break
  fi
}

你可能感兴趣的:(she‘ll,linux,服务器,java)