利用case语句

利用case语句:
#!/bin/bash
read -p "please input a number:" A
read -p "please input a number:" B
while getopts ":abcd" SWITCH; do
 case $SWITCH in
      a) echo "$[$A+$B]"
         ;;
      b) echo "$[$A-$B]"
         ;;
     c) echo "$[$A*$B]"
        ;;
    d) echo "$[$A/$B]"
        ;;
    \?) echo "unkonwn option"
        ;;
  esac
done
 

getopts:
#!/bin/bash
while getopts ":a:bc" SWITCH; do
  case $SWITCH in
a) echo "-a option"
   echo "$OPTARG"
  ;;
b)  echo "-b option"
  ;;
c) echo "-c option"
  ;;
\?) echo "unkown option"
  ;;
esac
done

 

你可能感兴趣的:(case,职场,语句,休闲)