The echo Command
echo is like a parrot for your computer: whatever you give it, it says back out loud on the screen.
In this page:
Syntax
echo [-n] [-e] "text"
The echo Command
echo prints text to standard output, optionally followed by a newline. It supports flags like -n (no trailing newline) and -e (interpret backslash escapes like \n and \t). It's the most basic way to produce output from a script.
Note:
Use
echo -e when you need escape sequences like \n to actually create a new line.Example: The echo Command
#!/bin/bash
echo "Hello, Bash!"
echo -n "No newline after this"
echo ""
echo -e "Line1\nLine2\tTabbed"
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
Common Mistakes
- Expecting
echo "a\nb"to print two lines, when Bashechoneeds-eto interpret\n. - Leaving a variable unquoted, as in
echo $name, so spaces and wildcard characters are expanded. - Forgetting that
echo -n(no newline) is used to stay on the same line.
🔒
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: