Unix-commands-echo
echo- Unix、Linuxコマンド
NAME
概要
説明
エコーは、コマンドラインを提供するほとんどのオペレーティングシステムに見られる基本的なコマンドです。 スクリプト、バッチファイル、および個々のコマンドの一部として頻繁に使用されます。テキストを挿入する必要がある場所。 bash、ksh、cshなどの多くのコマンドシェルは、組み込みコマンドとしてechoを実装しています。
オプション
Tag | Description |
---|---|
-n | Do not output a trailing newline. |
-e | Enable interpretation of backslash escape sequences (see below for a list of these). |
-E | Disable interpretation of backslash escape sequences (this is the default). |
--help | Display a help message and exit. |
--version | Output version information and exit. |
\\ | A literal backslash character ("\"). |
\a | An alert (The BELL character). |
\b | Backspace |
\c | Produce no further output after this. |
\e | The escape character; equivalent to pressing the escape key. |
\f | A form feed. |
\n | A newline. |
\r | A carriage return |
\t | A horizontal tab. |
\v | A vertical tab. |
\0NNN | byte with octal value NNN (which can be 1 to 3 digits). |
\xHH | byte with hexadecimal value HH (which can be either 1 or 2 digits) |
例
例-1:
文字列「Hello、World!」を出力するにはコンソールで
$ echo "Hello、World!"
output: Hello、World!
例-2:
xの値を出力するには、x = 10です。
$ echo $ x
output: 10
例-3:
オプション「 \ b 」を使用します。バックスラッシュインタプリタ「 -e 」を含むバックスペースは、間にあるすべてのスペースを削除します。
$ echo -e 'Here \ bthe \ bspaces \ bare \ bbackspaced。'
output: Herethespacesarebackspaced。
例-4:
オプション「\ n」を使用-バックスペースインタープリターを使用した新しい行「-e」は、使用されている場所からの新しい行を処理します。
$ echo -e 'こちら\ nthe \ nspaces \ nare \ nnewlined。
output: Herethespacesは改行されます。
例5:
オプション「\ t」–バックスペースインタプリタ付きの水平タブ「-e」を使用して、水平タブスペースを設定します。
$ echo -e 'ここ\ tthe \ tspaces \ thave \ thorizontal \ ttab \ tspaces。
出力:ここでスペースには水平方向タブスペースがあります。
例6:
オプション「 \ v 」–バックスペースインタプリタ付きの垂直タブ「 -e 」を使用して、垂直タブスペースを設定します。
$ echo -e 'ここ\ vthe \ vspaces \ vhave \ vvertical \ vtab \ vspaces'
output:ここではスペースが垂直タブスペースを持っています。
例-7:
オプション「\ r」–バックスペースインタープリター「-e」を使用したキャリッジリターンを使用して、出力でキャリッジリターンを指定します。
$ echo -e 'ここで、この前の\ rcontentが削除されます。
これが削除される前のoutput: content。
例-8:
オプション「 \ c 」を使用-バックスペースインタープリター「 -e 」で末尾の改行を抑制して、改行を出力せずに続行します。
$ echo -e「ここでは、「、」の後のコンテンツは印刷されません、\ cこれはコンソールに印刷されません」
output:ここでは、の後のコンテンツは印刷されません、
- 例-9: *
echoコマンドを使用してすべてのファイル/フォルダーを印刷するには(lsコマンドの代替)。
ubuntu @ ubuntu:/usr $ echo*
output: binゲームにはlibローカルsbin共有srcが含まれます
例-10:
標準出力ではなくファイルに出力をエコーします。 以下の例では、出力はテストファイルにリダイレクトされます。
$ echo "Hello World!" >テスト
output: $ cat testHello World!
link:/cgi-bin/printpage.cgi [__印刷]