2

I recently came across the following statement (source; emphasis added):

For shell scripts, using tabs is not a matter of preference or style; it's how the language is defined.

I am trying to make sense of this claim. Of course, it is somewhat loosely worded1, but I would like to know if there is any truth to it.

In particular, I would like to know if the official documentation for either bash or zsh (the two shells I routinely write scripts for) say anything approaching a mandate or recommendation to use tabs for indentation of source code. (I would appreciate explicit references to the supporting paragraphs in this documentation.)

(FWIW, let me point out that I am aware of the fact that, in practice, both bash and zsh readily interpret scripts that are not indented exclusively with tabs. Therefore, I don't expect the documentation for either shell to go much further than a strong recommendation, if they mention the matter at all.)


1 For one thing, it refers simultaneously to "shell scripts" and "the language", which contradicts the facts that there are multiple shells in current use, each defining its own language.

2
  • 1
    I edited the SO answer to clarify that it is only referring to heredocs and not to shell scripts in general.
    – terdon
    Commented Oct 25, 2022 at 14:26
  • 1
    it says "the shell language" without specification, but that question is tagged for Bash, so it's a safe assumption that they mean the language Bash accepts. Or the POSIX shell language, which is the relevant part here.
    – ilkkachu
    Commented Oct 25, 2022 at 14:56

1 Answer 1

4

As I understand it, the claim is being made specifically in the context of here-documents, and the <<- form specifically strips leading tabs:

If the redirection operator is "<<-", all leading <tab> characters shall be stripped from input lines and the line containing the trailing delimiter.

Note that the second script in that answer doesn’t use tabs, which would be surprising if the author considered that indentation was required to use tabs.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .