bdrockwell |
11-16-2010 10:50 PM |
if...elif...else BASH ladder problems
Our assignment is to take in two numbers and add them. While the inputs will always be numbers, we are to inform the user if they are doing it wrong.
My code:
Quote:
#!/bin/sh
if [[ -n "$3" ]]
then
echo too many inputs
elif [[ -z "$1"]]
then
echo you need to have two inputs
elif [[ -z "$2" ]]
then
echo you need to have two inputs
else
echo $1 + $2 = `expr $1 + $2`
fi
|
My error:
Quote:
[brockwel@darrow1-p hw5]$ problem1.sh
problem1.sh: line 6: syntax error in conditional expression
problem1.sh: line 7: syntax error near `then'
problem1.sh: line 7: `then'
|
The code worked fine before I tried to idiot-proof it. I'll probably end up nesting the if statements checking if the first two inputs are not null, but I'm more annoyed at why the script isn't working.
Help would be very appreciated.
|