In Bash, we can use echo or printf command to display a text in the console or terminal. Each commands have their own behaviors.
Newline in Bash:
Newline in Bash is expressed using the character "\n" with escape sequence. This is used to specify the end of line and to go to the next line.
Printing Newline using Echo:
The echo command is used to display a line of text on the terminal. We can also use the echo command to write text to a file by providing the string after the echo command and redirecting to the file.
$ echo -e "Printing\nNewline\nUsing\nEcho"
The above code is used to prints the text in newline using echo.
When using echo command for newline we should use -e flag to interpret backslash characters.
Printing Newline using Printf:
The printf command also prints the string on the console screen. It can be used as an alternative to the echo command.
$ printf "Printing\nNewline\nUsing\nPrintf"
The above code is used to prints the text in newline using printf.
Comments (0)