'\" 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 ユーティリティーは、 空白文字で区切られ、 復帰改行 ( NEWLINE ) で終わる引数を標準出力に出力します。引数が指定されていない場合は、NEWLINE 文字のみを書き出します。 .sp .LP \fBecho\fR は、コマンドファイル内で診断メッセージを生成したり、 既知のデータをパイプに送ったり、 環境変数の内容を表示したりする際に便利です。 .sp .LP C シェル、Korn シェル、Bourne シェル には、\fBecho\fR 組み込みコマンドがあります。 デフォルトでは \fBecho\fR 組み込みコマンドは、ユーザーがフルパス名なしで echo を呼び出した場合に実行されます。\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 の \fBecho\fR と \fB/usr/ucb/echo\fR には \fB-n\fR オプションが付きますが、バックスラッシュのついたエスケープ文字は認識しません。\fBsh\fR と \fBksh88\fR は、\fB/usr/ucb/echo\fR が最初に \fBPATH\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 用紙送り (form-feed) .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 は、\fBASCII\fR コードを 1、2、または 3 桁の 8 進数で表した 8 ビット文字です。 .RE .RE .SH 使用法 .sp .LP 移植性の必要なアプリケーションには、 \fB-n\fR ( 第 1 の引数として ) またはエスケープシーケンスを 使用しないでください。 .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 新しいアプリケーションでは \fBecho\fR の代わりに \fBprintf\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 以下に、復帰改行 ( NEWLINE ) なしで文字列を表示するための別の方法を示します。 .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 シェル .sp .in +2 .nf example$ \fBecho "$USER's current directory is $PWD\ec"\fR .fi .in -2 .sp .LP \fB例 4 \fRcsh シェル .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>\fB0\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 _ CSI有効 _ インタフェースの安定性確実 _ 標準T{ \fBstandards\fR(5) を参照してください。 T} .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 の前に必ずゼロ (\fB0\fR) を付けなければなりません。\fB\fR .sp .LP たとえば、\fBecho 'WARNING:\ 07'\fR と入力した場合、\fBWARNING:\fR が出力され、端末の “ベル” が鳴ります。“07” の前に “ \” を付けるときには、これを保護する単一 ( または二重 ) 引用符 ( または 2 つのバックスラッシュ ) を使用する必要があります。 .sp .LP \fB\0\fR の後には、 8 進の出力文字を形成する最大 3 桁の文字が使用されます。\fB\0\fR\fIn\fR の後に、 この 8 進表記に含まれない数値をさらに表示したい場合は、 \fIn\fR には全 3 桁を使用しなければなりません。たとえば、“ESC 7” と表示したい場合は、\fB\ 0\fR の後に、2 桁の “33” だけでなく、 3 桁の “033” を使用しなければなりません。 .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 各文字の 8 進表記については、\fBascii\fR(5) を参照してください。