I'm trying to add 1 number from the command line, and one number as like a default.
For example:
When user types in the number 50 the script will add 10 ( as the default number).
./script 50
The sum of 50+ 10 is 60.
This is what I have so far.
echo -n "Please enter a number: "
read number
default = 10
sum = $((default + number)) // this line does not seem to work
echo "The sum of $number and 10 is $sum."
Do I have the syntax wrong? I'm not sure if I'm on the right track. Am I adding the numbers wrong? Should I use awk instead?
let sum = $default + $number
Best Answer
Spaces are causing the errors.
If you want user to input the number when he is prompted as "Please enter a number:", you can use your script with some corrections as:
Check:
If you want the user to input the number as an argument to the script, you can use the script below:
Check: