Just to be clear, is this a
bash script, a POSIX-compliant
sh script, or something else? The syntax you're using appears to be
bash.
1) POSIX function declaration syntax is "
funcname()". In
bash you can also use "
function funcname". Use one or the other, not both. Although
bash won't complain if you do, other shells may not be so nice.
2) If possible, I would instead first split the FUNPATH into an array. Then you can simply use a
for loop to iterate over the entries for the search. Use a
break command to exit the loop when/if a match is found.
3) Instead of multiple separate
if statements, you should probably combine them into a single
if..elif..else.
4)
basename can be replaced with a simple parameter substitution. ( "${path##*/}" )
5) Finally, be consistent. If the shell supports "
[[..]]", then use that exclusively. Except also that in
bash/
ksh, numeric comparisons should be done with "
((..))" instead.
http://mywiki.wooledge.org/BashFAQ/031
http://mywiki.wooledge.org/ArithmeticExpression