diff --git a/sources/tech/20140822 15 Practical Examples of 'echo' command in Linux.md b/translated/tech/20140822 15 Practical Examples of 'echo' command in Linux.md similarity index 50% rename from sources/tech/20140822 15 Practical Examples of 'echo' command in Linux.md rename to translated/tech/20140822 15 Practical Examples of 'echo' command in Linux.md index c660812622..6b906232b1 100644 --- a/sources/tech/20140822 15 Practical Examples of 'echo' command in Linux.md +++ b/translated/tech/20140822 15 Practical Examples of 'echo' command in Linux.md @@ -1,44 +1,41 @@ -Translating-----------geekpi - - -15 Practical Examples of ‘echo’ command in Linux +Linux中15个‘echo’ 实例 ================================================================================ -**echo** is one of the most commonly and widely used built-in command for Linux bash and C shells, that typically used in scripting language and batch files to display a line of text/string on standard output or a file. +**echo**是一种最常用的与广泛使用的内置于Linux的bash和C shell的命令,通常用在脚本语言和批处理文件中来在标准输出或者文件中显示一行文本或者字符串。 ![echo command examples](http://www.tecmint.com/wp-content/uploads/2014/08/echo-command.png) -echo command examples +echo命令例子 -The syntax for echo is: +echo命令的语法是: - echo [option(s)] [string(s)] + echo [选项] [字符串] -**1.** Input a line of text and display on standard output +**1.** 输入一行文本并显示在标准输出上 $ echo Tecmint is a community of Linux Nerds -Outputs the following text: +会输出下面的文本: Tecmint is a community of Linux Nerds -**2.** Declare a variable and echo its value. For example, Declare a variable of **x** and assign its value=**10**. +**2.** 声明一个变量并输出它的值。比如,声明变量**x**并给它赋值为**10**。 $ x=10 -echo its value: +会输出它的值: $ echo The value of variable x = $x The value of variable x = 10 -**Note:** The ‘**-e**‘ option in Linux acts as interpretation of escaped characters that are backslashed. +**注意:** Linux中的选项‘**-e**‘扮演了转义字符反斜线的翻译器。 -**3.** Using option ‘**\b**‘ – backspace with backslash interpretor ‘**-e**‘ which removes all the spaces in between. +**3.** 使用‘**\b**‘选项- ‘**-e**‘后带上'\b'会删除字符间的所有空格。 $ echo -e "Tecmint \bis \ba \bcommunity \bof \bLinux \bNerds" TecmintisacommunityofLinuxNerds -**4.** Using option ‘**\n**‘ – New line with backspace interpretor ‘**-e**‘ treats new line from where it is used. +**4.** 使用‘**\n**‘选项- ‘**-e**‘后面的带上‘\n’行会在遇到的地方作为新的一行 $ echo -e "Tecmint \nis \na \ncommunity \nof \nLinux \nNerds" @@ -50,13 +47,13 @@ echo its value: Linux Nerds -**5.** Using option ‘**\t**‘ – horizontal tab with backspace interpretor ‘**-e**‘ to have horizontal tab spaces. +**5.** 使用‘**\t**‘选项 - ‘**-e**‘后面跟上‘\t’会在空格间加上水平制表符。 $ echo -e "Tecmint \tis \ta \tcommunity \tof \tLinux \tNerds" Tecmint is a community of Linux Nerds -**6.** How about using option new Line ‘**\n**‘ and horizontal tab ‘**\t**‘ simultaneously. +**6.** 也可以同时使用换行‘**\n**‘与水平制表符‘**\t**‘。 $ echo -e "\n\tTecmint \n\tis \n\ta \n\tcommunity \n\tof \n\tLinux \n\tNerds" @@ -68,7 +65,7 @@ echo its value: Linux Nerds -**7.** Using option ‘**\v**‘ – vertical tab with backspace interpretor ‘**-e**‘ to have vertical tab spaces. +**7.** 使用‘**\v**‘选项 - ‘**-e**‘后面跟上‘\v’会加上垂直制表符。 $ echo -e "\vTecmint \vis \va \vcommunity \vof \vLinux \vNerds" @@ -80,7 +77,7 @@ echo its value: Linux Nerds -**8.** How about using option new Line ‘**\n**‘ and vertical tab ‘**\v**‘ simultaneously. +**8.** 也可以同时使用换行‘**\n**‘与垂直制表符‘**\v**‘。 $ echo -e "\n\vTecmint \n\vis \n\va \n\vcommunity \n\vof \n\vLinux \n\vNerds" @@ -99,45 +96,45 @@ echo its value: Nerds -**Note:** We can double the vertical tab, horizontal tab and new line spacing using the option two times or as many times as required. +**注意:** 你可以按照你的需求连续使用两个或者多个垂直制表符,水平制表符与换行符。 -**9.** Using option ‘**\r**‘ – carriage return with backspace interpretor ‘**-e**‘ to have specified carriage return in output. +**9.** 使用‘**\r**‘选项 - ‘**-e**‘后面跟上‘\r’来指定输出中的回车符。 $ echo -e "Tecmint \ris a community of Linux Nerds" is a community of Linux Nerds -**10.** Using option ‘**\c**‘ – suppress trailing new line with backspace interpretor ‘**-e**‘ to continue without emitting new line. +**10.** 使用‘**\c**‘选项 - ‘**-e**‘后面跟上‘\c’会抑制输出后面的字符并且最后不会换新行。 $ echo -e "Tecmint is a community \cof Linux Nerds" - Tecmint is a community avi@tecmint:~$ + Tecmint is a community @tecmint:~$ -**11.** Omit echoing trailing new line using option ‘**-n**‘. +**11.** ‘**-n**‘会在echo完后不会输出新行。 $ echo -n "Tecmint is a community of Linux Nerds" - Tecmint is a community of Linux Nerdsavi@tecmint:~/Documents$ + Tecmint is a community of Linux Nerds@tecmint:~/Documents$ -**12.** Using option ‘**\a**‘ – alert return with backspace interpretor ‘**-e**‘ to have sound alert. +**12.** 使用‘**\c**‘选项 - ‘**-e**‘后面跟上‘\a’选项会听到声音警告。 $ echo -e "Tecmint is a community of \aLinux Nerds" Tecmint is a community of Linux Nerds -**Note:** Make sure to check Volume key, before firing. +**注意:** 在你开始前,请先检查你的音量键。 -**13.** Print all the files/folder using echo command (ls command alternative). +**13.** 使用echo命令打印所有的文件和文件夹(ls命令的替代)。 $ echo * 103.odt 103.pdf 104.odt 104.pdf 105.odt 105.pdf 106.odt 106.pdf 107.odt 107.pdf 108a.odt 108.odt 108.pdf 109.odt 109.pdf 110b.odt 110.odt 110.pdf 111.odt 111.pdf 112.odt 112.pdf 113.odt linux-headers-3.16.0-customkernel_1_amd64.deb linux-image-3.16.0-customkernel_1_amd64.deb network.jpeg -**14.** Print files of a specific kind. For example, let’s assume you want to print all ‘**.jpeg**‘ files, use the following command. +**14.** 打印制定的文件类型。比如,让我们假设你想要打印所有的‘**.jpeg**‘文件,使用下面的命令。 $ echo *.jpeg network.jpeg -**15.** The echo can be used with redirect operator to output to a file and not standard output. +**15.** echo可以使用重定向符来输出到一个文件而不是标准输出。 $ echo "Test Page" > testpage @@ -145,58 +142,58 @@ echo its value: avi@tecmint:~$ cat testpage Test Page -### echo Options ### +### echo 选项 ###
Options | -Description | +选项 | +描述 |
-n | -do not print the trailing newline. | +不输出末尾的换行符。 | |
-e | -enable interpretation of backslash escapes. | +启用反斜线转义。 | |
\b | -backspace | +退格 | |
\\ | -backslash | +反斜线 | |
\n | -new line | +新行 | |
\r | -carriage return | +回车 | |
\t | -horizontal tab | +水平制表符 | |
\v | -vertical tab | +垂直制表符 |