远行的心 发表于 2018-8-20 12:50:59

shell 之case

  在shell 脚本中,除了用if来判断逻辑外,还有一种常用的方式,那就是case了。具体格式为:
  case 变量in
  value1)
  command
  ;;
  value2)
  command
  ;;
  value3)
  command
  ;;
  *)
  command
  ;;
  esac
  举例:
  # cat case.sh
  #/bin/bash
  read -p "input a number:" n
  a=$[$n%2]
  case $a in
  1)
  echo "the unm is odd"
  ;;
  0)
  echo "the unm is even"
  ;;
  *)
  echo "it is not a num"
  ;;
  esac

页: [1]
查看完整版本: shell 之case