Echo new line in linux - supress new line or echo multiple new lines
Unix implementation of the "echo" command appends a new line character at the end of the echoed text by default.
It can be changed to supress this behavior using the "-n" switch.
Echo can also be used to output one or multiple new lines with the "-e" switch which will make echo interpret "\n" sequence as new line.
Below is a list of multiple options and special sequences with ECHO:
Quote:
DESCRIPTION
Echo the STRING(s) to standard output.
-n do not output the trailing newline
-e enable interpretation of backslash escapes
-E disable interpretation of backslash escapes (default)
--help display this help and exit
--version
output version information and exit
If -e is in effect, the following sequences are recognized:
\\ backslash
\a alert (BEL)
\b backspace
\c produce no further output
\e escape
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\0NNN byte with octal value NNN (1 to 3 digits)
\xHH byte with hexadecimal value HH (1 to 2 digits)
NOTE: your shell may have its own version of echo, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports.
Supress new line with echo:Code:
user@linux:~# echo -n "this is a sentence"
this is a sentenceuser@linux:~#
Echo one or multiple new lines
Code:
user@linux:~# echo -e "Two new lines following this\n\nAnother sentence"
Two new lines following this
Another sentence