1. 程式人生 > >shell計算腳本

shell計算腳本

use read printf second bin sage enter sed opera

#!/bin/bash
print_usage () {
printf "please enter an inteper \n"
}
read -p "Please input first number:" firstnum
while [ "echo "$firstnum" | sed -r ‘s#[^0-9]##g‘" != "$firstnum" ]
do
print_usage
read firstnum
done
read -p "Please input the operators:" operators
while [ "$operators" != "+" ]&&[ "$operators" != "-" ]&&[ "$operators" != "" ]&&[ "$operators" != "/" ]
do
read -p "please use + -
/" operators
done
read -p "Please input second number:" secondnum
while [ "echo "$secondnum" | sed -r ‘s#[^0-9]##g‘" != "$secondnum" ]
do
print_usage
read secondnum
done
echo "${firstnum}${operators}${secondnum} =$((${firstnum}${operators}${secondnum}))"
echo "$$" >/var/run/jsq.pid

shell計算腳本