views:

41

answers:

2

Are there any shell (specifically bash or ksh) checkers that test shell scripts for style, best practices, naming conventions, etc? (Something like Lint for C, or Perl::Critic for Perl.)

I know with ksh you can do syntax checking by running ksh -n script.ksh but I was hoping for something more than just sytax checking - something that parses/analyzes the actual code?

I'm probably out of luck, but I guess it doesn't hurt to ask.

Thanks in advance!

+2  A: 

The Debian and Ubuntu projects us a script checkbashisms, that look for particular patterns that might indicate that someone is relying on /bin/sh being bash.

Beyond that, most shells have a -n option to parse and report errors. You could check your script against several different shells to make sure it uses only portable syntax:

for shell in zsh ksh bash dash sh
do
  echo "Testing ${shell}"
  ${shell} -n my_script.sh
end
Brian Campbell
Cool - that script looks promising! And judging by my lack of finding anything else, and the lack of responses, I'd say that's probably the only thing out there that does this type of thing. Thanks very much!
BrianH
+1  A: 

I'm working on such a project, called loker. You can help if you wish, or just cheer me and I'll devote more time to it. :)

We're going to have complete POSIX-compliant parser soon, which is useful by itself, because a lot of so-called "shell scripts" are not POSIX-compliant even syntactically.

Roman Cheplyaka