Shell script formatting is nearly always a matter of style rather than technical need. For example it really doesn't matter if you write your subroutines as
Code:
doit(){
echo hello world
}
or
Code:
doit()
{
echo hello world
}
In my opinion, and it's just my opinion, the important point is maintainablility. In short, if you come back to this script in two years time will you be able to understand it. As such my personal rules are
1) Have a house style and stick to it. It doesn't matter what you chose as long as it's consistent.
2) Comment you code in a meaningful fashion.
3) Use meaningful variable names.
4) Annote amendments with what was changed and why.
5) Leave pleanty of white space
Items 1 - 4 are pretty much common sense, item 5 is my personal taste.
I agree with Columb - particularly the comments. There's no overhead (apart from a few bytes) to explaining what the code is doing in some detail. There's nothing worse than coming back to a piece of code two years later and wondering 'Now why did I do that?'.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.