Software Development with Linux

Be specific

TUE, 01 JUN 2010

Be specific when using system tools in scripts. Don't assume the default behavior will be the same everywhere, every time, for ever.

It's fine to not specify every options when you manually run a command. If the behavior is not what you wanted, you can re-execute it right away. But in scripts, there's no reason to not be specific, and put every options possible, to get the exact result that you want. There's no point in saving typing, since it is in a script anyway.

So, instead of
... | tail
... | tail -n 10
and instead of
df -kP
The same advice is valid for function calls too. If you depend on the default behavior, you must be sure that there's absolutely nothing in there that can affect your code. Since this is rarely the case, you should specify what you expect.

This way, without too much work, your scripts and code will be much more portable and much more future proof.

Just my 2 cents.