I have had to write a script that can execute 2 command line arguments to execute task. In addition to a while-loop. I am having trouble with the if statement on line 16. The shell produces the following:
./asg6s: line 16: syntax error near unexpected token fi'
'/asg6s: line 16:fi
My code is as follows:
#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
#check if input file is empty
if [ ! -s $FILE ] ; then
echo "$1 is empty"
exit 1
fi
# copy contents of first file to second
cat $1 > $2
while true
do
clear
# display the menu
echo "University of Maryland."
echo "purpose of using the app"
echo -en '\n'
echo "Choose one of the following:"
echo "1 Addition"
echo "2 Subtraction"
echo "3 Multiplication"
echo "4 Division"
echo "5 Modulo"
echo "0 Exit"
echo -en '\n'
#take input for 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 progam 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 $NAME. The result of $NAME $A and $B is" `expr $A $OP $B` > $2
done
Any help would be appreciated.
Edit:
In the same code above I have been getting a problem with the loop statement. Well I should say the fact that I cannot get the program to print the answer for me after I input to integers into the program. Specifically, it does nothing and goes back to the point where it ask me input for what operation I want to complete. Any help would be appreciated.
$FILEhere? Purely a guess but maybe it should be$1, as per the lines above it.#!/bin/bash(or whatever)). So then you have to play the binary search, commenting out code until you isolate what is causing the problem. Agree with above that if there is anything else above (not shown here), that may be the source of your problem, although the line# 16 seems to match with your code.