What is the preferred method to echo a blank line in a shell script?
echo
is preferred. echo " "
outputs an unnecessary space character. echo ""
would be better, but it's unnecessary.
but you can use
echo -e "Hi \n"
and print a blank line after Hi, with -e interprets the \n character.
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.
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"
.