010-150 · Question #75
Which option will cause the echo command NOT to output a trailing newline?
The correct answer is C. -n. The -n option suppresses the trailing newline that echo appends by default to its output.
Question
Which option will cause the echo command NOT to output a trailing newline?
Options
- A-e
- B-p
- C-n
- D-s
How the community answered
(14 responses)- A14% (2)
- B7% (1)
- C71% (10)
- D7% (1)
Why each option
The -n option suppresses the trailing newline that echo appends by default to its output.
-e enables interpretation of backslash escape sequences such as \n and \t within the string, which is the opposite behavior from suppressing output characters.
-p is not a recognized option for the echo command in standard Linux shells or GNU coreutils.
When echo is called with the -n flag, it omits the trailing newline character that would normally follow the output string. This is useful in shell scripts when you need to print a prompt or concatenate output on the same line, and it is supported by both the bash built-in echo and the GNU coreutils standalone echo binary.
-s is not a valid option for echo - it is used in other commands such as read to suppress echoed input.
Concept tested: echo command option to suppress trailing newline
Source: https://www.gnu.org/software/coreutils/manual/html_node/echo-invocation.html
Topics
Community Discussion
4C is your answer. The -n flag tells echo to suppress the trailing newline that it normally appends, which matters in scripts where you need output on the same line as user input or are concatenating strings without extra whitespace.
I kept second-guessing myself on -e before actually running echo -n in a shell and watching the prompt land right after the output.
-n suppresses the newline, and yeah, -e trips people up since it feels "special."
Worth adding for exam day, printf is the portable answer the test actually wants you to reach for when you need escape sequences, since echo -e behavior varies by shell and implementation.