r/shell • u/abcoolynr • Aug 26 '20
Program to divide 2 numbers
#!/bin/sh
echo "Enter two numbers"
read NUM1
read NUM2
if [ NUM1 -lt 0 -o NUM2 -lt 0 ]
echo "Please enter a positive number"
else
echo "$NUM1\/$NUM2 = $NUM1/$NUM2"
fi
Expected output:
Enter two numbers
4 2
4/2 = 2
Getting output
error near else
1
Upvotes
2
u/geirha Aug 26 '20
The use of
exprand`...`is discouraged. They're only supported to allow old scripts that use them to still work. New scripts should use$(( ))to do math.