echo
echo 是一個非常簡單递递、直接的 Linux 命令:
* 將 argument 送出至標準輸出(STDOUT),通常就是在監(jiān)視器(monitor)上輸出啥么。
目錄
[TOC]
查看echo幫助文檔
qmcui 18:05:08 ~
$ man echo|cat
ECHO(1) User Commands ECHO(1)
NAME
echo - display a line of text
SYNOPSIS
echo [SHORT-OPTION]... [STRING]...
echo LONG-OPTION
DESCRIPTION
Echo the STRING(s) to standard output.
-n do not output the trailing newline
-e enable interpretation of backslash escapes
-E disable interpretation of backslash escapes (default)
--help display this help and exit
--version
output version information and exit
If -e is in effect, the following sequences are recognized:
\\ backslash
\a alert (BEL)
\b backspace
\c produce no further output
\e escape
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\0NNN byte with octal value NNN (1 to 3 digits)
\xHH byte with hexadecimal value HH (1 to 2 digits)
NOTE: your shell may have its own version of echo, which usually supersedes the version
described here. Please refer to your shell's documentation for details about the options it
supports.
AUTHOR
Written by Brian Fox and Chet Ramey.
REPORTING BUGS
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report echo translation bugs to <http://translationproject.org/team/>
COPYRIGHT
Copyright ? 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to
the extent permitted by law.
SEE ALSO
Full documentation at: <http://www.gnu.org/software/coreutils/echo>
or available locally via: info '(coreutils) echo invocation'
GNU coreutils 8.25 February 2016 ECHO(1)
舉個簡單例子
$ echo
$
你會發(fā)現(xiàn)只有一個空白行登舞,然后又回到 shell prompt 上了。
這是因為echo會在輸出的結束悬荣,默認輸出一個換行菠秒。如果不想它輸入換行符執(zhí)行下面代碼
-n參數(shù):取消行末之換行符號(與 -e 選項下的 \c 字符一樣)
qmcui 18:01:42 ~
$ echo a
a
qmcui 18:01:58 ~
$ echo -n a
aqmcui 18:02:09 ~
# 注意看區(qū)別
-e :啟用反斜線控制字符的轉換(參考下表)
qmcui 18:09:06 ~
$ echo -e "a\tb\tc\nd\te\tf"
a b c
d e f
qmcui 18:11:58 ~
$ echo -e "\x61\x09\x62\x09\x63\x0a\x64\x09\x65\x09\x66"
a b c
d e f
qmcui 18:12:05 ~
$ echo -ne "a\tb\tc\nd\te\bf\a"
a b c
d fqmcui 18:13:36 ~
因為 e 字母后面是刪除鍵(\b),因此輸出結果就沒有 e 了氯迂。
在結束時聽到一聲鈴向践叠,那是 \a 的杰作﹗
-E:關閉反斜線控制字符的轉換(默認如此)
輸出功能
$ A=B
$ echo $A
B
$ echo $?
0