{"id":18822,"date":"2022-10-04T16:00:05","date_gmt":"2022-10-04T16:00:05","guid":{"rendered":"https:\/\/linuxways.net\/?p=18822"},"modified":"2022-11-04T02:46:07","modified_gmt":"2022-11-04T02:46:07","slug":"echo-command-bash-scripts-linux-mint-21","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/mint\/echo-command-bash-scripts-linux-mint-21\/","title":{"rendered":"How to Use the Echo Command in Bash Scripts in Linux Mint 21?"},"content":{"rendered":"<p><a id=\"post-18822-_Hlk114229268\"><\/a> \u201cEcho is a very interesting command in Linux that prints everything that you wish on the terminal. This command can be used directly within the terminal. However, you can even use it inside Bash scripts. In this article, we will be discussing the usage of this command within the Bash scripts in Linux Mint 21.\u201d<\/p>\n<h2><strong>Examples of Using the Echo Command in Bash Scripts in Linux Mint 21<\/strong><\/h2>\n<p>To teach you the usage of the Echo command in Bash scripts in Linux Mint 21, we have designed the following three examples for you:<\/p>\n<h3><strong>Example # 1: Printing a Simple Message on the Terminal<\/strong><\/h3>\n<p>In this example, we will create a Bash script that will make use of the Echo command to print a simple message on the terminal. For that, we have created the Bash script shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"651\" height=\"180\" class=\"wp-image-18845\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-1.png 651w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-1-300x83.png 300w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><\/p>\n<p>To execute this Bash script, we ran the following command in the terminal:<\/p>\n<pre>\r\n$ bash echo.bash\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"346\" height=\"22\" class=\"wp-image-18846\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-2.png 346w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-2-300x19.png 300w\" sizes=\"auto, (max-width: 346px) 100vw, 346px\" \/><\/strong><\/p>\n<p>The message printed on the terminal is shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"370\" height=\"63\" class=\"wp-image-18851\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-3.png 370w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-3-300x51.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n<h3><strong>Example # 2: Printing the Result of a Calculation on the Terminal<\/strong><\/h3>\n<p>Now, we will go a step further and create a complex Bash script, as shown in the following image:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"646\" height=\"245\" class=\"wp-image-18857\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-4.png 646w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-4-300x114.png 300w\" sizes=\"auto, (max-width: 646px) 100vw, 646px\" \/><\/p>\n<p>In this script, we have created two variables, \u201ca\u201d and \u201cb,\u201d and have assigned them two different values, i.e., 2 and 4. Then, we have created another variable, \u201csum,\u201d and have equalized it to the expression \u201c$((a+b))\u201d that will store the sum of \u201ca\u201d and \u201cb\u201d to the \u201csum\u201d variable. Finally, we have used an Echo command to print the sum of \u201ca\u201d and \u201cb\u201d on the terminal.<\/p>\n<p>When we executed this Bash script with the same command that has been shared in the example above, the value of \u201csum\u201d appeared on the terminal, as shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"353\" height=\"63\" class=\"wp-image-18859\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-5.png 353w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-5-300x54.png 300w\" sizes=\"auto, (max-width: 353px) 100vw, 353px\" \/><\/p>\n<h3><strong>Example # 3: Making a User Interactive Program<\/strong><\/h3>\n<p>Now, we will try to make an interactive program with the help of the Echo command in Bash that will take some input from the user and then display the results accordingly. The following Bash script will serve this purpose:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"647\" height=\"213\" class=\"wp-image-18862\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-6.png 647w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-6-300x99.png 300w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/p>\n<p>This Bash script will prompt the user to enter his name in the terminal. After that, this name will be processed by the \u201cread\u201d command. Then, this Bash script will greet the user with his\/ her name by making use of the Echo command.<\/p>\n<p>When we executed this script by using the command shared in our first example, we were prompted to enter the user name as shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"367\" height=\"51\" class=\"wp-image-18864\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-7.png 367w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-7-300x42.png 300w\" sizes=\"auto, (max-width: 367px) 100vw, 367px\" \/><\/p>\n<p>The name that we entered is shown in the following image:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"353\" height=\"67\" class=\"wp-image-18865\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-8.png 353w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-8-300x57.png 300w\" sizes=\"auto, (max-width: 353px) 100vw, 353px\" \/><\/p>\n<p>Once we entered a user name, a greeting message was printed on the terminal, as shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"368\" height=\"96\" class=\"wp-image-18867\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-9.png 368w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/10\/word-image-18822-9-300x78.png 300w\" sizes=\"auto, (max-width: 368px) 100vw, 368px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>In this article, we discussed the different usage scenarios of the Echo command within the Bash scripts in Linux Mint 21. Once you go through all these examples, you will realize how easy it is to use this command in Linux.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>Echo is an interesting command in Linux that prints everything that you wish on the terminal. How to use the Echo command in Bash Scripts is discussed.<\/p>","protected":false},"author":3,"featured_media":18881,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-18822","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mint"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=18822"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18822\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/18881"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=18822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=18822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=18822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}