-4

I'm currently trying to add an empty line in here, the example of the command that I have so far

echo -e "my kernel version is $(uname -a) \nand the current date is $(date)"

how do I change the whole thing, so the output of this is

my kernel version is Linux centos7 3.10.0-1127.18.2.el7.x86_64 #1 SMP Sun Jul 26 15:27:06 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
*** empty line***   
and the current date is Fri Apr 23 09:18:29 EEST 2021
αғsнιη
  • 41,407

2 Answers2

0

This uses a here-document to output the multi-line message (the empty line is created by including an empty line in the here-document):

cat <<END
my kernel version is $(uname -a)

and the current date is $(date) END

This uses printf to output the message (the empty line is created by outputting two consecutive newlines):

printf 'my kernel version is %s\n\nand the current date is %s\n' "$(uname -a)" "$(date)"

On my system, both of these produce the text

my kernel version is OpenBSD box.prefix.example.com 6.9 GENERIC.MP#473 amd64

and the current date is Fri Apr 23 17:03:24 CEST 2021

See also: Why is printf better than echo?

Kusalananda
  • 333,661
0

I agree that printf is more versatile than echo, but a quick modification is:

FROM:

echo -e "my kernel version is $(uname -a) \nand the current date is $(date)"

TO:

echo -e "my kernel version is $(uname -a) \n\nand the current date is $(date)"

Feel free to add as many newlines \n as you like for more white space.

Seamus
  • 2,925