← Back to Bash Course | Chapter 1: Setup & Basics | Lesson 5 of 12

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:

  1. The echo Command
Syntax
bash
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

bash
#!/bin/bash
echo "Hello, Bash!"
echo -n "No newline after this"
echo ""
echo -e "Line1\nLine2\tTabbed"
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
  1. Expecting echo "a\nb" to print two lines, when Bash echo needs -e to interpret \n.
  2. Leaving a variable unquoted, as in echo $name, so spaces and wildcard characters are expanded.
  3. Forgetting that echo -n (no newline) is used to stay on the same line.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.