Sign up ×
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
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

4 Answers 4

up vote 28 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

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

Just open the file with vim editor and typing gg=G will reindent the entire file. I think this is the standard.

share|improve this answer

Your Answer


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.