我对这个程序唯一的问题是打印等式的结果。当我尝试乘以3 * 3然后打开我得到的输出文件:
echo操作是倍增的。乘以3和3的结果是
代码如下:
#!/bin/ksh
#check if number of arguments are 2
if [ $# -ne 2 ]; then
echo "Does not equal two arguments"
echo "Usage $0 inputfile outputfile"
exit 1
fi
#check if input file exists
if [ ! -e $1 ]; then
echo "$1 not found!"
exit 1
fi
#copy contents of first file to secon
cat $1 > $2
#While loop
while true
do
clear
#display the menu
echo " University of Maryland "
echo " App to solve integer equation "
echo -en '\n'
echo " 1: Addition"
echo " 2: Subtraction"
echo " 3: Multiplication"
echo " 4: Division"
echo " 5: Modulo"
echo " 0: Exit"
echo -en '\n'
echo " Pleasa choose one of the following: "
#take input from operation
read N
case $N in
1) NAME="add";OP="+";;
2) NAME="subtract";OP="-";;
3) NAME="multiply";OP="*";;
4) NAME="divide";OP="/";;
5) NAME="modulo";OP="%";;
0) echo "The program is ending" ; exit 0;;
*) echo " Not an acceptable entry." ;continue;
esac
#take input numbers
echo "Enter two numbers"
read A
read B
#display value on screen and also append in the output file
echo "The operation is to $NAME. The result of $NAME $A and $B is `expr $A $OP $B`
echo The operation is to multiply. The result of multiply 3 and 3 is
echo "The operation is to $NAME. The result of $NAME $A and $B is `expr $A $OP $B` > $2
done
我无法弄清楚出了什么问题。一切似乎都在正确的地方。
答案 0 :(得分:1)
我刚刚回答了你原来的问题:
结果出现在while循环再次调用clear之前。
请参阅另一个答案:在双引号中使用“$ OP”,您不希望*被文件列表替换。