2020-07-09 21:30:44 +01:00
|
|
|
|
# echo
|
|
|
|
|
|
2021-08-02 09:41:09 +01:00
|
|
|
|
> 输出给定参数。
|
2021-08-31 08:13:49 +01:00
|
|
|
|
> 更多信息:<https://www.gnu.org/software/coreutils/echo>.
|
2020-07-09 21:30:44 +01:00
|
|
|
|
|
2021-08-02 09:41:09 +01:00
|
|
|
|
- 输出文本信息. 注意: 引号是可选的:
|
2020-07-09 21:30:44 +01:00
|
|
|
|
|
2020-10-04 18:33:38 +01:00
|
|
|
|
`echo "{{Hello World}}"`
|
2020-07-09 21:30:44 +01:00
|
|
|
|
|
2021-08-02 09:41:09 +01:00
|
|
|
|
- 输出带有环境变量的信息:
|
2020-07-09 21:30:44 +01:00
|
|
|
|
|
2020-10-04 18:33:38 +01:00
|
|
|
|
`echo "{{My path is $PATH}}"`
|
2020-07-09 21:30:44 +01:00
|
|
|
|
|
|
|
|
|
- 打印不带尾随换行符的信息:
|
|
|
|
|
|
2020-10-04 18:33:38 +01:00
|
|
|
|
`echo -n "{{Hello World}}"`
|
2020-07-09 21:30:44 +01:00
|
|
|
|
|
2021-08-02 09:41:09 +01:00
|
|
|
|
- 向文件添加信息:
|
2020-07-09 21:30:44 +01:00
|
|
|
|
|
2020-10-04 18:33:38 +01:00
|
|
|
|
`echo "{{Hello World}}" >> {{file.txt}}`
|
2020-07-09 21:30:44 +01:00
|
|
|
|
|
2021-08-02 09:41:09 +01:00
|
|
|
|
- 启用反斜杠转义的解释(特殊字符):
|
2020-07-09 21:30:44 +01:00
|
|
|
|
|
2020-10-04 18:33:38 +01:00
|
|
|
|
`echo -e "{{Column 1\tColumn 2}}"`
|
2023-10-31 18:33:04 +00:00
|
|
|
|
|
|
|
|
|
- 输出执行的上一条指令的退出状态(注:在 Windows 命令提示符和 PowerShell 中,对应的命令分别是 `echo %errorlevel%` 和 `$lastexitcode`):
|
|
|
|
|
|
|
|
|
|
`echo $?`
|