Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the preferred method to echo a blank line in a shell script?

Tags:

bash

shell

I am currently writing some code for a shell script that needs a blank line between two parts of the script, as thus they can be separated when output is displayed to the user.

My question is, I am not sure what the preferred practice is in a shell script for a blank line.

Is it preferred practice to just write echo and nothing else or to write echo " " as in echo with quotes and blank between the quotes?

like image 960
jgr208 Avatar asked May 05 '16 14:05

jgr208


People also ask

How do I echo a blank line in shell script?

There are a couple of different ways we can print a newline character. The most common way is to use the echo command. However, the printf command also works fine. Using the backslash character for newline “\n” is the conventional way.

Can you have blank lines in bash script?

Blank lines are also considered to be lines, so don't start your script with an empty line. As noted before, this implies that the Bash executable can be found in /bin.

How do I print a blank line in Linux?

echo is used to produce a new line in Linux. echo -e '\n\n' 3 lines and so on. e.g.


2 Answers

echo is preferred. echo " " outputs an unnecessary space character. echo "" would be better, but it's unnecessary.

like image 86
John Kugelman Avatar answered Oct 05 '22 15:10

John Kugelman


but you can use

echo -e "Hi \n"  

and print a blank line after Hi, with -e interprets the \n character.

like image 37
wyanez Avatar answered Oct 05 '22 17:10

wyanez