To print multiple lines using echo in Bash, the -e option and the newline escape sequence \n are used.
Code
echo -e "This is the first line.\nThis is the second line.\nAnd this is the third line."
Explanation:
echo: The command used to display lines of text or strings.
-e: This option enables the interpretation of backslash escapes, such as \n for a newline. Without -e, \n would be printed literally as \n.
"\n": This is the newline escape sequence. When interpreted by echo -e, it creates a line break.
Output of the example:
Code
This is the first line.
This is the second line.
And this is the third line.
Alternatively, printf can be used, which offers more control over formatting and is often considered more portable across different shells:
Code
printf "This is the first line.\nThis is the second line.\nAnd this is the third line.\n"
Note that printf does not automatically add a newline at the end of the output, so \n must be explicitly included if a final newline is desired.