Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

closed as primarily opinion-based by X Tian, cuonglm, Anthon, dr01, G-Man Oct 7 '15 at 13:14

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the 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
The standard is to use whitespace. – Anthon Oct 7 '15 at 10:32
shameless plug: let bash itself decide of the proper indentation automagically: unix.stackexchange.com/questions/274888/… – Olivier Dulac Apr 7 at 12:40
up vote 29 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
Historically four spaces per indentation level might arguably the most common. – con-f-use Nov 20 '15 at 22:22

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

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