2

Or how can I ensure reliability of my Makefiles/scripts?

Update: by shell scripts I mean sh dialect (bash, zsh, whatever), by Makefiles I mean GNU make. I know, they are different beasts, but they have many in common.

P. S. Yeah, I know, static code analysis can't verify all possible cases, and that I need to write my Makefiles and shell script in a way, that would be reliable. I just need tool, that will tell me, when I use bad practices, when I forgot about them or didn't notice in big script. Not fix errors for me, but just take second look.

Makoto
  • 104,088
  • 27
  • 192
  • 230
evgeniuz
  • 2,599
  • 5
  • 30
  • 36
  • A static code analyzer is not going to tell you whether your code is *reliable*. Reliability is achieved through automatic and/or manual testing. What are you trying to do? Do you mean something like `pylint` style programs, which kind of check for *readability*? – l0b0 May 15 '12 at 09:30
  • "Testng in reliability"? [This is like "testing in quality"] I don't think that's how you get reliability. You get reliability by designing your application (C# or makefile) to run properly with good input data in a variety of expected circumstances, and reasonable sanity tests on input data. What OP is hoping for IMHO is a tool that tells him his make / scripts will fail under a variety of common circumstances, so that he can address those issues. – Ira Baxter May 15 '12 at 10:05
  • 2
    Shark: This is really two very different questions, as "scripting" languages and "makefiles" have extremely different syntax, and radically different semantics. Both have "difficult" parsing issues, in that macros/string substitutions tend to be everywhere in complex scripts; unless the analysis tool can repeat all of these, it will have a hard time knowing what got said let alone whether it is said incorrectly. – Ira Baxter May 15 '12 at 10:11
  • Shark: I think you need to be clear about *which* scripting langauge (there's a zillion of them), and which dialect of make. (GNU? classic unix? MS nmake? ....) – Ira Baxter May 15 '12 at 10:15
  • @IraBaxter updated question slightly. they are different, but have many in common, so I would leave this as one question, I feel this is right. If moderators want, they could separate this in two questions. – evgeniuz May 15 '12 at 11:09
  • The SH question is already here: http://stackoverflow.com/questions/3668665/is-there-a-static-analysis-tool-like-lint-or-perlcritic-for-shell-scripts – user123444555621 May 15 '12 at 11:10
  • 1
    The moderators aren't going to *do* anything; only you will. I think you seriously misunderstand how different a scripting language from makefiles; they have completely different execution semantics. – Ira Baxter May 15 '12 at 11:31

1 Answers1

1

For sh scripts, ShellCheck will do some static analysis checks, like detecting when variable modifications are hidden by subshells, when you accidentally use [ $foo=bar ] or when you neglect to quote variables that could contain spaces. It also comments on some stylistic issues like useless use of cat or using sed when you could use parameter expansion.

that other guy
  • 116,971
  • 11
  • 170
  • 194