On Wed, Oct 08, 2025 at 03:52:24 -0400, Craig H Maynard wrote:
> In my Bash scripts, I indent using spaces instead of tabs but I'd still like
> to get this behavior. Why not strip leading whitespace?
Because that's not how it's defined to work.
https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_07_04
If the redirection operator is "<<-", all leading <tab> characters
shall be stripped from input lines after <backslash><newline> line
continuation (when it applies) has been performed, and from the
line containing the trailing delimiter. Stripping of leading <tab>
characters shall occur as the here-document is read from the shell
input (and consequently does not affect any <tab> characters that
result from expansions).
If you want rationale, consider this: how would you perform the
equivalent of the following under your proposed change?
cat <<-'EOF'
usage: myprogram [-q] [-f file]
Options:
-q Quiet mode (suppress progress messages)
-f file Read from file instead of standard input
EOF
I.e. each line is indented with one tab, which is intended to be
removed. Some lines have spaces after the tab, and those spaces
are intended to be preserved.
To get the equivalent of your proposed change without modifying the
shell in a way that would violate the definitions, you could replace
cat with sed:
sed 's/^[[:space:]]*//' <<-'EOF'
These lines
are indented
with spaces
EOF
The only eyesore would be the delimiter word, which can't be indented
with spaces.