I am very new to Linux and am taking a course in it. Very excited to learn more. I am working on a script that asks user for two numbers, then asks whether user wants to add or subtract. I failed the assignment, but am still trying to figure out where I went wrong. I'm sure it's something obvious and stupid, but I can't see it.
This is one place I am sure I am messing up. I declared two variables at top, but I suspect that's not where they should be.
Here is the rest of it. When I debug, I can tell it does the math, but I cannot get it to print the answer to the console.
sum=$(expr "$number1" + "$number2")
difference=$(expr "$number1" - "$number2")
echo "Please enter your first number
read number1
echo "Please enter your second number."
read number2
echo "Enter S if you want to Subtract, A if you want to Add."
read request
case " $request" in
"A") echo "$sum";;
"S") echo "$difference";;
*) "Sorry, that is an invalid request.";;
esac
number1
andnumber2
. You appear to be expecting some sort of delayed evaluation - which doesn't happen in bash, AFAIK (although you might be able to implement a hacky version usingeval
). – steeldriver May 29 '16 at 22:43