The following codepiece is a script used to install Apache. I run this script in-place when executing it from the heredoc block that wraps it (APACHE).
Note that inside this APACHE heredoc, I have an internal heredoc (MOD_REWRITE), which I can refer to as a "secondary" or "internal" heredoc.
Please also note that all the code inside APACHE is indented (tabulated), besides the code of the internal heredoc.
bash /dev/fd/10 10<<'APACHE' # Setup basics: apt-get update -y && apt-get upgrade -y apt-get install tree zip unzip a2enmod mcrypt && a2enmod mbstring # Setup LAMP environment with enabled mod rewrite: echo -e "\07" && echo -e "\077" # Insert password. apt-get install lamp-server^ -y a2enmod rewrite cat <<MOD_REWRITE >> /etc/apache2/apache2.conf <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> MOD_REWRITE systemctl restart apache2.service # Setup maldet: cd /usr/local/src wget http://www.rfxn.com/downloads/maldetect-current.tar.gz && tar -xzf maldetect-current.tar.gz cd maldetect-* && bash ./install.sh APACHE
If I indent it with commands with spaces instead of tabulations, I can run the script just fine (as long as it doesn't have the MOD_REWRITE inside it). If I add the MOD_REWRITE, the script brakes when executed; The same happens if I remove all space-indents whatsoever and totally replace them with tabulations, but AFAIK, the last time I tried to execute the script with tabulations, it also broke (even when I added an hyphen between
bash /dev/fd/10 10<< and
What is the right way to indent the MOD_REWRITE heredoc inside the APACHE heredoc, so the script would be more unified and would execute without breakage?
The reason I want to indent internal heredocs as well, just as I would do with any other command, is from aesthetic reasons --- It makes it easier for me to read and organize my scripts.
This question is not the same as "Can't indent heredoc to match nesting's indent" because it asks about the correct way of indenting internal heredocs inside external heredocs, and not about indenting external heredocs themselves.