Privacy Policy
© 2025 linux101.dev

echo Command Cheatsheet

The echo command is a fundamental utility used to display a line of text or a string to the standard output. It's often used in shell scripts to output status messages or to display the value of a variable.

Basic Usage

CommandDescription
echo "Hello World"Prints the string "Hello World" to the terminal.
echo $SHELLDisplays the value of the environment variable `$SHELL`. This is one of the most common use cases for `echo`.

Redirection with `echo`

You can use `echo` in combination with redirection to write text to a file.

CommandDescription
echo "Hello" > file.txtWrites (and overwrites) the text "Hello" into a file named `file.txt`.
echo "New line" >> file.txtAppends the text "New line" to the end of `file.txt` without overwriting the existing content.

Escape Sequences

The `-e` option enables the interpretation of backslash escapes, which is useful for formatting output.

# Prints "Hello" and "World" on separate lines
echo -e "Hello\nWorld"