This is a computer written by the shell, support add, subtract, multiply, divide, take the mold, and provide user input content detection, share to everyone.
#!/bin/bash #这是一个计算器! read -p "Please enter the first number:" -t 30 num1 read -p "Please enter the second number:" -t 30 num2 read -p "Please enter the operation symbol (support + - * / %): " -t 30 op if [ -n " $num 1 " -a -n "$num 2" -a -n "$op" ] then n1=$ (echo $num 1 | sed ' s/[0-9]//g ') n2=$ (echo $num 2 | sed ' s/[0-9]//g ') if [ -z "$n 1" -a -z " $n 2 " ] then case $op in "+") r=$ (($num 1 + $num 2) ;; "-") r=$ (($num 1 - $num 2) ;; "*") r=$ (($num 1 * $num 2)) ;; "/") r=$ (($num 1 / $num 2) ;; "%") r=$ (($num 1 % $num 2)) ;; *) echo "Please enter the correct operator!" " exit 10 ;; esac else echo "Please enter the correct number!" " exit 11 fi else echo "Please enter the correct content!" " exit 12 fi echo " $num 1$op$ Num2= $R "
Write a simple computer using the shell