Search code examples
bashprintfindentation

Indenting in a Bash script printf command without the indent coming out in the output


I want to indent in my bash script so that my script looks more organized, but don't want the spaces to print.

If I have the command

printf "<image>
        <<include etc/image.conf>>
        </image>" > file.txt

I want file.txt to look like

<image>
<<include etc/image.conf>>
</image>

instead of

<image>
        <<include etc/image.conf>>
        </image>

The problem is that I don't want my script to look like this

While Loop
      If Statement
                printf "<image>
<<include etc/image.conf>>
</image>" > file.txt
                Command Here
      End If
End While

I just want it to look a little bit neater


Solution

  • To keep the script more readable and prevent white spaces from getting in the way:

    printf "%s\n%s\n%s\n" "<image>" \
                          "<<include etc/image.conf>>" \
                          "</image>" > file.txt