'\" te .\" Copyright 1989 AT&T .\" Copyright (c) 2008, 2011, Oracle and/or its affiliates.All rights reserved. .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation.Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation.In the following statement, the phrase "this text" refers to portions of the system documentation.Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document.The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.This notice shall appear on any product containing this material. .TH echo 1 "2011 年 7 月 12 日" "SunOS 5.11" "用户命令" .SH 名称 echo \- 回显参数 .SH 用法概要 .LP .nf \fB/usr/bin/echo\fR [\fIstring\fR]... .fi .SH 描述 .sp .LP \fBecho\fR 实用程序可将其参数(用空格分隔并用换行符终止)写入到标准输出。如果没有参数,则仅写入换行符。 .sp .LP \fBecho\fR 适用于在命令文件中生成诊断、将已知数据发送到管道中以及显示环境变量的内容。 .sp .LP C shell、Korn shell 和 Bourne shell 都有 \fBecho\fR 内置命令;缺省情况下,如果用户调用 \fBecho\fR 时未提供完整路径名,将调用这些命令。请参见 \fBshell_builtins\fR(1)。\fBsh\fR 的 \fBecho\fR、\fBksh88\fR 的 \fBecho\fR、\fBksh\fR 的 \fBecho\fR 和 \fB/usr/bin/echo\fR 理解反斜杠转义符,但 \fBsh\fR 的 \fBecho\fR 不理解 \fB\a\fR 警报字符。此外,\fBksh88\fR 和 \fBksh\fR 的 \fBecho\fR 没有 \fB-n\fR 选项。另一方面,\fBcsh\fR 的 \fB echo\fR 和 \fB/usr/ucb/echo\fR 有一个 \fB-n\fR 选项,但不理解反斜杠转义符。\fBsh\fR 和 \fBksh88\fR 确定是否在 \fBPATH\fR 中先查找 \fB/usr/ucb/echo\fR;如果是,则调整内置的 \fBecho\fR 行为以匹配 \fB/usr/ucb/echo\fR。 .SH 操作数 .sp .LP 支持下列操作数: .sp .ne 2 .mk .na \fB\fIstring\fR\fR .ad .RS 10n .rt 要写入到标准输出的字符串。如果任一操作数为 “\fB-n\fR”,则将其视为字符串,而不是选项。在任何参数中都可识别以下字符序列: .sp .ne 2 .mk .na \fB\fB\a\fR\fR .ad .RS 7n .rt 警报字符。 .RE .sp .ne 2 .mk .na \fB\fB\b\fR\fR .ad .RS 7n .rt 退格。 .RE .sp .ne 2 .mk .na \fB\fB\c\fR\fR .ad .RS 7n .rt 列显不带换行符的行。忽略参数中 \fB\c\fR 后面的所有字符。 .RE .sp .ne 2 .mk .na \fB\fB\f\fR\fR .ad .RS 7n .rt 换页符。 .RE .sp .ne 2 .mk .na \fB\fB\n\fR\fR .ad .RS 7n .rt 换行符。 .RE .sp .ne 2 .mk .na \fB\fB\r\fR\fR .ad .RS 7n .rt 回车。 .RE .sp .ne 2 .mk .na \fB\fB\t\fR\fR .ad .RS 7n .rt 制表符。 .RE .sp .ne 2 .mk .na \fB\fB\v\fR\fR .ad .RS 7n .rt 垂直制表符。 .RE .sp .ne 2 .mk .na \fB\fB\\\fR\fR .ad .RS 7n .rt 反斜杠。 .RE .sp .ne 2 .mk .na \fB\fB\0\fR\fIn\fR\fR .ad .RS 7n .rt 其中 \fIn\fR 是 8 位字符,其 \fBASCII\fR 编码为代表该字符的 1 位、2 位 或 3 位数的八进制数字。 .RE .RE .SH 用法 .sp .LP 可移植应用程序不应使用 \fB-n\fR(作为第一个参数)或者转义序列。 .sp .LP \fBprintf\fR(1) 实用程序可通过移植方式用于模拟 \fBecho\fR 实用程序的任何传统行为,如下所示: .RS +4 .TP .ie t \(bu .el o Solaris 2.6 操作系统或兼容版本的 \fB/usr/bin/echo\fR 等效于: .sp .in +2 .nf \fBprintf "%b\en" "$*"\fR .fi .in -2 .sp .RE .RS +4 .TP .ie t \(bu .el o \fB/usr/ucb/echo\fR 等效于: .sp .in +2 .nf if [ "X$1" = "X-n" ] then shift printf "%s" "$*" else printf "%s\en" "$*" fi .fi .in -2 .RE .sp .LP 鼓励新应用程序使用 \fBprintf\fR 来取代 \fBecho\fR。 .SH 示例 .LP \fB示例 1 \fR查找当前目录距离根目录的层次 .sp .LP 可以使用 \fBecho\fR 确定在根目录 (\fB/\fR) 下方深入多少个子目录才是您的当前目录,如下所示: .RS +4 .TP .ie t \(bu .el o 回显当前工作目录的完整路径名。 .RE .RS +4 .TP .ie t \(bu .el o 通过 \fBtr\fR 传输输出,以便将路径的嵌入式斜杠字符转换为空格字符。 .RE .RS +4 .TP .ie t \(bu .el o 通过 \fBwc\fR \fB-w\fR 传输该输出以获路径中的名称数量。 .sp .in +2 .nf example% \fB/usr/bin/echo $PWD | tr '/' ' ' | wc -w\fR .fi .in -2 .sp .RE .sp .LP 有关它们的功能,请参见 \fBtr\fR(1) 和 \fBwc\fR(1)。 .sp .LP 以下是回显不带换行符的字符串的其他形式: .LP \fB示例 2 \fR/usr/bin/echo .sp .in +2 .nf example% \fB/usr/bin/echo "$USER's current directory is $PWD\ec"\fR .fi .in -2 .sp .LP \fB示例 3 \fRsh/ksh88 shell .sp .in +2 .nf example$ \fBecho "$USER's current directory is $PWD\ec"\fR .fi .in -2 .sp .LP \fB示例 4 \fRcsh shell .sp .in +2 .nf example% \fBecho -n "$USER's current directory is $PWD"\fR .fi .in -2 .sp .LP \fB示例 5 \fR/usr/ucb/echo .sp .in +2 .nf example% \fB/usr/ucb/echo -n "$USER's current directory is $PWD"\fR .fi .in -2 .sp .SH 环境变量 .sp .LP 有关影响 \fBuname\fR 执行的以下环境变量的说明,请参见 \fBenviron\fR(5):\fBLANG\fR、\fBLC_ALL\fR、\fBLC_CTYPE\fR、\fBLC_MESSAGES\fR 和 \fBNLSPATH\fR。 .SH 退出状态 .sp .LP 将返回以下错误值: .sp .ne 2 .mk .na \fB\fB0\fR\fR .ad .RS 6n .rt 成功完成。 .RE .sp .ne 2 .mk .na \fB\fB>0\fR\fR .ad .RS 6n .rt 出现错误。 .RE .SH 属性 .sp .LP 有关下列属性的说明,请参见 \fBattributes\fR(5): .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/core-os _ CSIEnabled(已启用) _ 接口稳定性Committed(已确定) _ 标准请参见 \fBstandards\fR(5)。 .TE .SH 另请参见 .sp .LP \fBksh\fR(1)、\fBprintf\fR(1)、\fBshell_builtins\fR(1)、\fBtr\fR(1)、\fBwc\fR(1)、\fBecho\fR(1B)、\fBascii\fR(5)、\fBattributes\fR(5)、\fBenviron\fR(5)、\fBstandards\fR(5) .SH 附注 .sp .LP 通过使用转义约定 \fB\0\fR\fIn\fR 表示 8 位字符时,\fIn\fR 前面必须\fB始终\fR有一个数字零 (\fB0\fR)。 .sp .LP 例如,键入 \fBecho 'WARNING:\ 07'\fR 将输出短语 \fBWARNING:\fR,并在终端上响铃。需要使用单引号或双引号(或者两个反斜杠)来保护 “07” 前面的 “ \”。 .sp .LP 在 \fB\0\fR 后面最多使用三个数字来构造八进制输出字符。如果在 \fB\0\fR\fIn\fR 后要回显不属于八进制表示形式的其他数字,则必须使用完整的三位数 \fIn\fR。例如,如果要回显 “ESC 7”,则必须在 \fB\ 0\fR 后使用三位数 “033”,而不是两位数 “33”。 .sp .in +2 .nf 2 digits Incorrect: echo "\e0337" | od -xc produces: df0a (hex) 337 (ascii) 3 digits Correct: echo "\e00337" | od -xc produces: lb37 0a00 (hex) 033 7 (ascii) .fi .in -2 .sp .sp .LP 有关每个字符的八进制等效字符,请参见 \fBascii\fR(5)。