Take the 2-minute tour ×

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
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:


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
+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


