On Wed, Oct 8, 2025, at 9:07 AM, Stan Marsh 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?
>
>>...
>>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 above "sed" solution doesn't really scale if your actual command
> is anything other than "cat"
It can scale perfectly well.
sed 's/^[[:space:]]*//' <<-'EOF' | actual_command
These lines
are indented
with spaces
EOF
It needs a little extra sauce if the actual command needs to modify
shell state:
mapfile -t < <(sed 's/^[[:space:]]*//' <<-'EOF'
These lines
are indented
with spaces
EOF
)
(Or use the "lastpipe" shopt.)
> (Yes, I know there will be objections to this statement, but it
> is true nonetheless)
Preemptively declaring your claim to be irrefutable is a bit
combative, don't you think?
> The real point is that OP is not the first person in the world to have
> noticed this glitch in the definition of here documents.
Here is a previous thread on the topic:
https://lists.gnu.org/archive/html/bug-bash/2021-08/msg00209.html
https://lists.gnu.org/archive/html/bug-bash/2021-09/msg00000.html
It's not a glitch; it's intentional behavior that some people happen
to not like.
> It is kind of like Makefile, where the same anomaly
> attaches -> tab(s) and nothing else.
Recent versions of GNU make allow choosing a different character
via the .RECIPEPREFIX variable.
https://www.gnu.org/software/make/manual/html_node/Special-Variables.html
> Like the weather, everybody complains, nobody does anything
> about it.
>
> It would probably be possible to add a new operator (e.g., <<--) to
> mean strip all leading whitespace, but I doubt it will ever be high
> enough on anyone's TODO list to get done.
Grisha contributed an implementation of ksh93's <<# operator
a couple of years ago, but Chet hasn't looked at it yet.
https://lists.gnu.org/archive/html/bug-bash/2023-07/msg00057.html
--
vq