#!/bin/bash compute() { if [ $# != 3 ];then echo "Your input num is not enough!" fi let "s=0" case $2 in +) let "s=$1+$3" echo "answer is: $s" ;; -) let "s=$1-$3" echo "answer is: $s" ;; \*) let "s=$1*$3" echo "answer is: $s" ;; \/) let "s=$1%$3" echo "answer is: $s" ;; *) echo "your input is wrong!" ;; esac } echo "Pls,input like this: 2 + 3" echo "" read a b c compute $a $b $c [[email protected] test]# ./fun3.sh 2 + 3 Pls,input like this: 2 + 3 3 + 3 answer is: 6
函数_实例2_计算器
时间: 2024-12-31 05:36:44