Bash from scratch --again
Your script has a syntax error; it lacks one more fi
at the end.
Once this error is fixed, you get the "unary operator expected", because your $1
value (the value of the first parameter of the script) is empty, and the first if
command expects that value to be non-empty. You must call the script with some number as a parameter, like:
./script 150
Then you get the response:
You typed a larger number
And it's even an even number
If you want the script to not display error messages when called with no parameter, before using the parameter you must detect whether the parameter is empty and do something. For example you can add the following code before your first if
command:
if [ -z "$1" ]
then
echo "Parameter required!"
exit
fi