I am just starting to learn UNIX and i could not figure the problem here can you please point out the error
age=30 if [[ $age -lt 18 ]] then echo "not eligible" elif [[ $age -gt 18 && $age -lt 60 ]] echo "eligible" else echo "stay home" fi exit
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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
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