{"id":13582,"date":"2019-04-03T11:09:24","date_gmt":"2019-04-03T11:09:24","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13582"},"modified":"2019-04-03T11:09:24","modified_gmt":"2019-04-03T11:09:24","slug":"15-practical-examples-of-echo-command-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/15-practical-examples-of-echo-command-in-linux\/","title":{"rendered":"15 Practical Examples of \u2018echo\u2019 command in Linux"},"content":{"rendered":"<p><strong><span data-ft=\"{&quot;tn&quot;:&quot;K&quot;}\" data-reactid=\".dy.1:3:1:$comment851505914867870_851514128200382:0.0.$right.0.$left.0.0.1:$comment-body\"><span class=\"UFICommentBody\" data-reactid=\".dy.1:3:1:$comment851505914867870_851514128200382:0.0.$right.0.$left.0.0.1:$comment-body.0\">echo<\/span><\/span><\/strong>\u00a0is 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.<\/p>\n<div id=\"attachment_8466\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/08\/echo-command.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8466\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/08\/echo-command.png\" alt=\"echo command\" width=\"442\" height=\"317\" aria-describedby=\"caption-attachment-8466\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-8466\" class=\"wp-caption-text\">echo command examples<\/p>\n<\/div>\n<p>The syntax for echo is:<\/p>\n<pre>echo [option(s)] [string(s)]\r\n<\/pre>\n<p><strong>1.<\/strong>\u00a0Input a line of text and display on standard output<\/p>\n<pre>$ echo Tecmint is a community of Linux Nerds \r\n<\/pre>\n<p>Outputs the following text:<\/p>\n<pre>Tecmint is a community of Linux Nerds \r\n<\/pre>\n<p><strong>2.<\/strong>\u00a0Declare a variable and echo its value. For example, Declare a variable of\u00a0<strong>x<\/strong>\u00a0and assign its value=<strong>10<\/strong>.<\/p>\n<pre>$ x=10\r\n<\/pre>\n<p>echo its value:<\/p>\n<pre>$ echo The value of variable x = $x \r\n\r\nThe value of variable x = 10 \r\n<\/pre>\n<p><strong>Note<\/strong>: The \u2018<strong>-e<\/strong>\u2018 option in Linux acts as interpretation of escaped characters that are backslashed.<\/p>\n<p><strong>3.<\/strong>\u00a0Using option \u2018<strong>\\b<\/strong>\u2018 \u2013 backspace with backslash interpretor \u2018<strong>-e<\/strong>\u2018 which removes all the spaces in between.<\/p>\n<pre>$ echo -e \"Tecmint \\bis \\ba \\bcommunity \\bof \\bLinux \\bNerds\" \r\n\r\nTecmintisacommunityofLinuxNerds \r\n<\/pre>\n<p><strong>4.<\/strong>\u00a0Using option \u2018<strong>\\n<\/strong>\u2018 \u2013 New line with backspace interpretor \u2018<strong>-e<\/strong>\u2018 treats new line from where it is used.<\/p>\n<pre>$ echo -e \"Tecmint \\nis \\na \\ncommunity \\nof \\nLinux \\nNerds\" \r\n\r\nTecmint \r\nis \r\na \r\ncommunity \r\nof \r\nLinux \r\nNerds \r\n<\/pre>\n<p><strong>5.<\/strong>\u00a0Using option \u2018<strong>\\t<\/strong>\u2018 \u2013 horizontal tab with backspace interpretor \u2018<strong>-e<\/strong>\u2018 to have horizontal tab spaces.<\/p>\n<pre>$ echo -e \"Tecmint \\tis \\ta \\tcommunity \\tof \\tLinux \\tNerds\" \r\n\r\nTecmint \tis \ta \tcommunity \tof \tLinux \tNerds \r\n<\/pre>\n<p><strong>6.<\/strong>\u00a0How about using option new Line \u2018<strong>\\n<\/strong>\u2018 and horizontal tab \u2018<strong>\\t<\/strong>\u2018 simultaneously.<\/p>\n<pre>$ echo -e \"\\n\\tTecmint \\n\\tis \\n\\ta \\n\\tcommunity \\n\\tof \\n\\tLinux \\n\\tNerds\" \r\n\r\n\tTecmint \r\n\tis \r\n\ta \r\n\tcommunity \r\n\tof \r\n\tLinux \r\n\tNerds \r\n<\/pre>\n<p><strong>7.<\/strong>\u00a0Using option \u2018<strong>\\v<\/strong>\u2018 \u2013 vertical tab with backspace interpretor \u2018<strong>-e<\/strong>\u2018 to have vertical tab spaces.<\/p>\n<pre>$ echo -e \"\\vTecmint \\vis \\va \\vcommunity \\vof \\vLinux \\vNerds\" \r\n\r\nTecmint \r\n        is \r\n           a \r\n             community \r\n                       of \r\n                          Linux \r\n                                Nerds \r\n\r\n<\/pre>\n<p><strong>8.<\/strong>\u00a0How about using option new Line \u2018<strong>\\n<\/strong>\u2018 and vertical tab \u2018<strong>\\v<\/strong>\u2018 simultaneously.<\/p>\n<pre>$ echo -e \"\\n\\vTecmint \\n\\vis \\n\\va \\n\\vcommunity \\n\\vof \\n\\vLinux \\n\\vNerds\" \r\n\r\n\r\nTecmint \r\n\r\nis \r\n\r\na \r\n\r\ncommunity \r\n\r\nof \r\n\r\nLinux \r\n\r\nNerds \r\n<\/pre>\n<p><strong>Note<\/strong>: We can double the vertical tab, horizontal tab and new line spacing using the option two times or as many times as required.<\/p>\n<p><strong>9.<\/strong>\u00a0Using option \u2018<strong>\\r<\/strong>\u2018 \u2013 carriage return with backspace interpretor \u2018<strong>-e<\/strong>\u2018 to have specified carriage return in output.<\/p>\n<pre>$ echo -e \"Tecmint \\ris a community of Linux Nerds\" \r\n\r\nis a community of Linux Nerds \r\n<\/pre>\n<p><strong>10.<\/strong>\u00a0Using option \u2018<strong>\\c<\/strong>\u2018 \u2013 suppress trailing new line with backspace interpretor \u2018<strong>-e<\/strong>\u2018 to continue without emitting new line.<\/p>\n<pre>$ echo -e \"Tecmint is a community \\cof Linux Nerds\" \r\n\r\nTecmint is a community avi@tecmint:~$ \r\n<\/pre>\n<p><strong>11.<\/strong>\u00a0Omit echoing trailing new line using option \u2018<strong>-n<\/strong>\u2018.<\/p>\n<pre>$ echo -n \"Tecmint is a community of Linux Nerds\" \r\nTecmint is a community of Linux Nerdsavi@tecmint:~\/Documents$ \r\n<\/pre>\n<p><strong>12.<\/strong>\u00a0Using option \u2018<strong>\\a<\/strong>\u2018 \u2013 alert return with backspace interpretor \u2018<strong>-e<\/strong>\u2018 to have sound alert.<\/p>\n<pre>$ echo -e \"Tecmint is a community of \\aLinux Nerds\" \r\nTecmint is a community of Linux Nerds\r\n<\/pre>\n<p><strong>Note<\/strong>: Make sure to check Volume key, before firing.<\/p>\n<p><strong>13.<\/strong>\u00a0Print all the files\/folder using echo command (ls command alternative).<\/p>\n<pre>$ echo * \r\n\r\n103.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 \r\n<\/pre>\n<p><strong>14.<\/strong>\u00a0Print files of a specific kind. For example, let\u2019s assume you want to print all \u2018<strong>.jpeg<\/strong>\u2018 files, use the following command.<\/p>\n<pre>$ echo *.jpeg \r\n\r\nnetwork.jpeg \r\n<\/pre>\n<p><strong>15.<\/strong>\u00a0The echo can be used with redirect operator to output to a file and not standard output.<\/p>\n<pre>$ echo \"Test Page\" &gt; testpage \r\n\r\n## Check Content\r\navi@tecmint:~$ cat testpage \r\nTest Page \r\n<\/pre>\n<h5>echo Options<\/h5>\n<table border=\"0\" cellspacing=\"0\">\n<tbody>\n<tr>\n<td align=\"LEFT\" height=\"16\"><b>\u00a0Options<\/b><\/td>\n<td align=\"LEFT\"><b>\u00a0Description<\/b><\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"16\"><b>\u00a0-n<\/b><\/td>\n<td align=\"LEFT\">\u00a0do not print the trailing newline.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"16\"><b>\u00a0-e<\/b><\/td>\n<td align=\"LEFT\">\u00a0enable interpretation of backslash escapes.<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"16\"><b>\u00a0\\b<\/b><\/td>\n<td align=\"LEFT\">\u00a0backspace<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"16\"><b>\u00a0\\\\<\/b><\/td>\n<td align=\"LEFT\">\u00a0backslash<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"16\"><b>\u00a0\\n<\/b><\/td>\n<td align=\"LEFT\">\u00a0new line<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"16\"><b>\u00a0\\r<\/b><\/td>\n<td align=\"LEFT\">\u00a0carriage return<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"16\"><b>\u00a0\\t<\/b><\/td>\n<td align=\"LEFT\">\u00a0horizontal tab<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"16\"><b>\u00a0\\v<\/b><\/td>\n<td align=\"LEFT\">\u00a0vertical tab<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>That\u2019s all for now and don\u2019t forget to provide us with your valuable feedback in the comments below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>echo\u00a0is 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 command examples The syntax for echo is: echo [option(s)] [string(s)] 1.\u00a0Input a line of text and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/15-practical-examples-of-echo-command-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;15 Practical Examples of \u2018echo\u2019 command in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13582","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13582"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13582\/revisions"}],"predecessor-version":[{"id":13583,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13582\/revisions\/13583"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}