Reputation:
I am new to shell scripting and stuck in some syntax error in a simple program. I read an integer and compare it with some value to display the result Please tell me how to rectify it.
#! /bin/bash
read n
if [ "$n" -le 12 ]
then
echo "a kid"
elif[ "$n" -lt 18 ]
then
echo "a teen"
else
echo "an adult"
fi
The error was:
./hello.sh: line 8: syntax error near unexpected token `then'
./hello.sh: line 8: `then'
Upvotes: 3
Views: 48
Reputation: 2401
You're missing a space between elif
and [
, which causes a parsing error later on.
For future reference, the shellcheck tool is a good way to diagnose errors like this one.
Upvotes: 4