There are a couple of issues with your script, but the most pressing one is the lack of then
after the second test.
You also have an unnecessary test for $age -gt 18
, which additionally introduces a logical error. You already know that $age
is less than 18 at that point, and you accidentally leave out the case of $age
being precisely 18. It would be better to remove the $age -gt 18
test altogether.
The script will not need the explicit call to exit
at the end but should have a #!
-line at the top pointing to the appropriate shell interpreter (probably bash
).
You may find https://www.shellcheck.net/ a helpful site for finding the most basic errors in scripts.
#!/bin/bash
age=30
if [[ $age -lt 18 ]]; then
echo 'not eligible'
elif [[ $age -lt 60 ]]; then
echo 'eligible'
else
echo 'stay home'
fi
https://shellcheck.net
, a syntax checker, or installshellcheck
locally. Make usingshellcheck
part of your development process.$age -gt 18
... the firstif
statement takes care of that$age -gt 18 &&
would make a difference ifage
is 18, but probably your suggestion is the correct one instead of telling the 18 year olds to stay at home with the over-60ies …