76

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?

6 Answers 6

98

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

Sign up to request clarification or add additional context in comments.

Comments

53

but you can use

echo -e "Hi \n" 

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

1 Comment

\n to make a blank line is cleaner in the code. Better than having a bunch of echo "". It's a matter of choice, but the code looks cleaner. For places where you need a blank line before and after a line of text use "\n line of text \n"
12

All of these commands can be used to echo a blank line:

echo, echo '', echo ""

We cant use echo "\n" or echo '\n' as they will give output as \n in both cases.

1 Comment

Depending on your shell you can do something like echo -en "\n"
10

In its first implementation, echo had no option and outputs optional arguments ending with a new line, so it perfectly suit your needs.

For formatted outputs ending with a new line, printf is a better choice, for example : printf "%s\n\n" "output".

Comments

4

printf

More portable and succinct. This prints a hundred lines.

shell

printf '\n%.0s' `seq 1 100` 

bash

printf '\n%.0s' {1,100} 

Comments

2

As John suggested use echo. However if you want to print a blank line followed by text and anther blank line - as in running a test then use echo -e suggested by wyanzes.

echo -e "\n Now we are going to load data \n"

puts a blank line before and after.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.