What does echo do on Linux? The echo builtin writes its arguments to
stdout, separated by spaces, then prints a trailing newline unless you turn
that off. The -n flag means “do not append that final newline,”
which is why prompts and progress text often use bash "echo -n" so the cursor
stays on the same line.
Output below was produced with Bash 5.2.37 on Ubuntu 25.04 (kernel 6.14.0-37-generic).
Default echo: one line, then a newline
echo "This is an echo example"This is an echo exampleThe shell prints the text, then drops to the next line because of the newline echo adds by default.
echo -n: same text, no trailing newline
printf '>'; echo -n "This is an echo example"; printf '<\n'>This is an echo example<Markers > / < show there is no newline between the sentence and the
following prompt—exactly the echo -n behavior people look up for Y/N prompts and status fragments.
echo n, bash echo n, and echo "-n" (easy mistakes)
echo nprints the literal lettern(one argument). It is not the same asecho -n(a flag plus more arguments).echo "-n" hellois a sharp edge: on GNU bash, the first argument"-n"is still treated like the-noption, so you may gethellowith no newline—not the text-n. To print a literal-n, useprintf '%s\n' -- '-n'(or another form that never treats the first column as anechoflag).
echo \n vs echo -e and real newlines
Single quotes keep backslashes literal; -e turns escapes on for bash echo:
echo 'foo\nbar'
echo -e 'foo\nbar'foo\nbar
foo
barSo bash echo \n searches often mix two ideas: a literal \n two-character
sequence versus an escaped newline, which needs -e (or $'…' ANSI-C
quoting: echo $'foo\nbar').
Small script: prompt on one line
#!/usr/bin/env bash
read -r -p "Do you want to quit? [Y]/N: " input
case ${input:-Y} in
[yY]) echo -n "Y" ;;
[nN]) echo -n "N" ;;
*) echo "[Y]/N" ;;
esac
echoread -p already keeps the question on one line; echo -n here only shows how
you might echo a choice without an extra blank line before the next command.
Prefer printf in portable scripts
echo flags and escape rules differ between bash, dash, and BSD
/bin/echo. For anything non-toy, printf is predictable:
printf 'Name: '
printf '%s\n' "$USER"See help echo / help printf in bash, or man 1 echo on your distro.
Related
- bash concatenate strings when building messages before printing.
- beginner Bash arguments
for scripts that wrap
echo. - Stack Overflow: How to NOT print a trailing newline after echo
Summary
What does echo do in linux: print arguments with spaces and a default trailing
newline. What is echo -n: skip that newline so the next output shares the
line—classic bash echo -n prompt trick. echo n is just printing n;
echo "-n" can still be parsed as an option on GNU bash, so use printf when
the data might start with -. For real newlines inside a string, use
echo -e '...\n...', $'…', or printf—not a bare echo \n unless you
understand how your shell quotes the backslash.

