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
| Command | Description |
|---|---|
echo "Hello World" | Prints the string "Hello World" to the terminal. |
echo $SHELL | Displays 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.
| Command | Description |
|---|---|
echo "Hello" > file.txt | Writes (and overwrites) the text "Hello" into a file named `file.txt`. |
echo "New line" >> file.txt | Appends 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"