What is the preferred method to echo a blank line

2019-04-04 13:06发布

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?

标签: bash shell
3条回答
We Are One
2楼-- · 2019-04-04 13:56

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".

查看更多
家丑人穷心不美
3楼-- · 2019-04-04 13:59

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.

查看更多
Luminary・发光体
4楼-- · 2019-04-04 14:02

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

查看更多
登录 后发表回答