← 返回命令列表

Linux command

echo 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Print text

echo "[Hello World]"

Print without trailing newline

echo -n "[text]"

Interpret escape sequences

echo -e "[Line 1\nLine 2]"

Print an environment variable

echo $[PATH]

Write text to a file

echo "[content]" > [file.txt]

Append text to a file

echo "[more content]" >> [file.txt]

说明

echo displays a line of text to standard output. It's one of the most basic and frequently used commands, essential for scripts, logging, and displaying information to users. The command exists as both a shell built-in and standalone program.

参数

-n
Don't output trailing newline
-e
Enable interpretation of backslash escapes
-E
Disable interpretation of backslash escapes (default)

FAQ

What is the echo command used for?

echo displays a line of text to standard output. It's one of the most basic and frequently used commands, essential for scripts, logging, and displaying information to users. The command exists as both a shell built-in and standalone program.

How do I run a basic echo example?

Run `echo "[Hello World]"` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -n do in echo?

Don't output trailing newline