Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I format a shell script ?

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
I have long shell scripts .
I would like to format the script to set correct indentation and spacing ?
 
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.

Columb Healy
 
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?'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top