I recently tried to use the <<- operator for heredocs in bash to keep indentation in my bash functions:
cat <<- EOF
Hello World
EOF
However it turns out this only strips literal tab characters before the strings, which is of no use to me since:
- Some code editors replace tabs with spaces right away. So when I save this text in nvim or vscode it will still keep the indentation
- the EOF still needs to be written left-bound, I can't indent it.
I also don't want to strip all whitespace, only the ones that match up to the height of the EOF delimiter. So this would be my use case:
#!/bin/bash
log_something() {
cat <<- EOF
This is not indented in the final document
This is indented by 4 spaces
EOF
}
log_something
Is something like this possible in modern bash?
spacein my setup, so indenting with 4 spaces of course yields an error.