If I have some nested and indented statements that echo a multi-line string into a file, the indents from the original shell (in my case bash) will be carried over into the target file.To avoid this, I remove indents from the echo'ed output, but this loses that indented code formatting in my source, for example,#! /bin/bashfunction configure_default_vhost() {    case $2 in        [--production])              echo <VirtualHost *:80># These lines are breaking out of the preffered indentingredirect 404 /ErrorDocument 404</VirtualHost> > /etc/apache/sites-availabe/000-default.conf    esac}I'm aiming to get something as close as possible to this:#! /bin/bashfunction configure_default_vhost() {    case $2 in        [--production])              echo <VirtualHost *:80>                    # These lines are aligned with the preffered indenting                    redirect 404 /                    ErrorDocument 404                    </VirtualHost>                     > /etc/apache/sites-availabe/000-default.conf    esac}(Note: this question has been listed as a possible duplicate of a HEREDOC related question. I'm not sure where the correct place to respond to this is so I'll put here for now (someone please let know if otherwise). My question is about indenting code blocks, and heredoc is only one of the many ways to acheive this and actually HEREDOC wasn't the solution I went with.)
Is it possible to echo into a file, but use indenting in the shell script source?
bash;shell script
Using echo with the -e switch ( enable the interpretation of backslash escapes):#!/bin/bashfunction configure_default_vhost() {    conf_file=/etc/apache/sites-availabe/000-default.conf    case $2 in        [--production])            # The > overwrites; the >> appends.             {                echo -e <VirtualHost *:80>                echo -e \tredirect 404 /                echo -e \tErrorDocument 404                echo -e </VirtualHost>            } > $conf_file    esac}