Skip to main content

Syntax

echo [OPTIONS] [STRING...]

Description

The echo command writes its arguments to standard output, separated by spaces and followed by a newline. It’s one of the most fundamental commands for displaying text, debugging scripts, and creating simple output. Unlike system shells, Nash’s echo runs entirely in-memory with no external process calls.

Options

-n
flag
Suppress the trailing newline. Output ends immediately after the last argument.
-e
flag
Enable interpretation of backslash escape sequences:
  • \n - newline
  • \t - horizontal tab
  • \r - carriage return
  • \\ - backslash

Examples

Basic output

echo Hello, World!
Hello, World!

Multiple arguments

echo one two three
one two three

Suppress trailing newline

echo -n "Loading"
echo "..."
Loading...

Using escape sequences

echo -e "Line 1\nLine 2\nLine 3"
Line 1
Line 2
Line 3

Tab-separated values

echo -e "Name\tAge\tCity"
echo -e "Alice\t30\tNew York"
Name    Age     City
Alice   30      New York

Variable expansion

echo "Current user: $USER"
echo "Home directory: $HOME"
Current user: user
Home directory: /home/user

Pipeline Examples

Create content for grep

echo -e "apple\nbanana\napricot" | grep ap
apple
apricot

Generate test data

echo "hello world" | wc -w
       2

Write to file

echo "Configuration data" > config.txt
cat config.txt
Configuration data

Append to file

echo "Line 1" > file.txt
echo "Line 2" >> file.txt
cat file.txt
Line 1
Line 2

Practical Use Cases

Script debugging

echo "Starting deployment..."
cp src/* dist/
echo "Deployment complete!"

Creating CSV data

echo "id,name,value" > data.csv
echo "1,Item A,100" >> data.csv
echo "2,Item B,200" >> data.csv

Status messages

test -f config.json && echo "Config found" || echo "Config missing"

Environment inspection

echo "PATH: $PATH"
echo "Working directory: $(pwd)"
  • cat - Display file contents
  • wc - Count lines, words, and bytes
Nash’s echo automatically expands variables like $VAR and command substitutions like $(cmd). Use single quotes to prevent expansion: echo '$HOME' outputs the literal text $HOME.

Build docs developers (and LLMs) love