In practical terms, there is no specific limit to the number of elif statements you can use in a shell script. You can have dozens or even hundreds if you really need to.
However, here are a few things to keep in mind:
1. Readability
If you find yourself writing 20 or 30 elif statements, your script can become very long and difficult to read. It becomes harder to track where the block starts and ends.
2. Performance
Bash evaluates elif conditions sequentially (from top to bottom). If you have 100 elif blocks and the match is the very last one, Bash has to perform 99 failed checks before it reaches the correct one.
3. Better Alternatives (The case statement)
When you have a long list of conditions checking the same variable (like checking the variable $NAME against many different strings), it is usually better to use a case statement instead.
For example, your current script could be rewritten like this:
case "$NAME" in
"John")
echo "John Lennon"
;;
"Paul")
echo "Paul McCartney"
;;
"George")
echo "George Harrison"
;;
*)
echo "Unknown member"
;;
esac
Summary: While you can use as many elif statements as you want, if the list gets too long, programmers usually switch to a case statement to keep the code clean and organized!