Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Java community use 4 spaces as the unit of indentation. 1
Ruby community use 2 spaces that is generally agreed-upon. 2

What's the standard for indentation in shell scripts? 2 or 4 spaces or 1 tab?

share|improve this question
13  
Standards are great. We've got so many of them to choose from... –  Shadur May 23 '12 at 9:39
    
For the funny, take a look at the "standard" indention for the scripts in /etc/init.d. You will find the two-spaces standard, four-spaces, one-tab, etc., used in different scripts, sometimes a couple of those standards in the same script. –  cjc May 23 '12 at 10:52
    
I normally use 2 spaces, and never had any readability problems. –  helpermethod May 23 '12 at 14:34
add comment

3 Answers

up vote 23 down vote accepted

There is no standard indentation in shell scripts that matters.

Slightly less flippant answer:

  • Pick a standard in your team that you can all work to, to simplify things.
  • Use something your editor makes easy so you don't have to fight to stick to the standard.
share|improve this answer
add comment

I've never encountered shell specified style guide but for bash programming this is the most popular one:

http://lug.fh-swf.de/vim/vim-bash/StyleGuideShell.en.pdf

The indentation of program constructions has to agree with the logic nesting depth. The indentation of one step usually is in line with the tabulator steps of the editor selected. In most cases 2, 4 or 8 are chosen.

share|improve this answer
2  
+1 for the guide url. It's a good starting point anyway. –  Joe May 25 '12 at 18:08
add comment

Google says 2 spaces: http://google-styleguide.googlecode.com/svn/trunk/shell.xml?showone=Indentation#Indentation

Agree with others that it is an arbitrary choice.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.