{"id":3086,"date":"2020-12-31T14:23:39","date_gmt":"2020-12-31T14:23:39","guid":{"rendered":"https:\/\/linuxways.net\/?p=3086"},"modified":"2020-12-31T15:00:35","modified_gmt":"2020-12-31T15:00:35","slug":"how-to-create-and-run-a-shell-script-in-linux-mint-20","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/mint\/how-to-create-and-run-a-shell-script-in-linux-mint-20\/","title":{"rendered":"How to Create and Run a Shell Script in Linux Mint 20"},"content":{"rendered":"<h2>Introduction:<\/h2>\n<p>A shell script is an alternative method of carrying out those operations automatically that have to be carried out quite frequently. Therefore, carrying them out manually is a hassle. Moreover, at times you have such complex scenarios for which you do not want to do the manual working every time such a scenario is encountered. Therefore, today we are going to tell you how you can create and run a shell script in Linux Mint 20. However, if you want to do the very same thing on any other Linux distribution, then you can take a look at our article on <a href=\"https:\/\/linuxways.net\/de\/debian\/how-to-create-and-run-a-shell-script-in-debian-10\/\">creating and running a shell script in Debian 10<\/a>.<\/p>\n<h2>Method of Creating a Shell Script in Linux Mint 20:<\/h2>\n<p>For creating a shell script in Linux Mint 20, we will first create a Bash file by running the following command:<\/p>\n<pre><strong>sudo nano Script.sh<\/strong><\/pre>\n<p>Here, you can replace Script with any name of your choice that you want to keep for your shell script. We have named our shell script as MyFirstShellScript.sh as shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"497\" height=\"26\" class=\"wp-image-3087\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-525.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-525.png 497w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-525-300x16.png 300w\" sizes=\"auto, (max-width: 497px) 100vw, 497px\" \/><\/p>\n<p>When an empty file will open with the nano editor, we will write a sample Bash script in it. The first line of this script indicates that it is a Bash script (you can also write \u201csh\u201d instead of \u201cbash\u201d over here). Then we have written the code to print a sample message on the terminal while using the \u201cecho\u201d command. You can display any random message of your choice.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"653\" height=\"127\" class=\"wp-image-3088\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-526.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-526.png 653w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-526-300x58.png 300w\" sizes=\"auto, (max-width: 653px) 100vw, 653px\" \/><\/p>\n<p>After saving your file, you can even confirm its creation by running the following command:<\/p>\n<pre><strong>ls<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"267\" height=\"23\" class=\"wp-image-3089\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-527.png\" \/><\/strong><\/p>\n<p>This command will list down the contents of your current directory in which you have created your shell script. The name of the newly created shell script is highlighted in the image shown below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"644\" height=\"408\" class=\"wp-image-3090\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-528.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-528.png 644w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-528-300x190.png 300w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/p>\n<p>Now, we can also check the contents of this script by running the following command:<\/p>\n<pre><strong>cat Script.sh<\/strong><\/pre>\n<p>Here, you have to replace Script with the name of your shell script whose contents you want to view.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"449\" height=\"23\" class=\"wp-image-3091\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-529.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-529.png 449w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-529-300x15.png 300w\" sizes=\"auto, (max-width: 449px) 100vw, 449px\" \/><\/p>\n<p>The contents of our first shell script are shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"520\" height=\"80\" class=\"wp-image-3092\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-530.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-530.png 520w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-530-300x46.png 300w\" sizes=\"auto, (max-width: 520px) 100vw, 520px\" \/><\/p>\n<h2>Method of Running a Shell Script in Linux Mint 20:<\/h2>\n<p>After creating a shell script and confirming its creation, we can look into the method of running it. We can run a shell script in Linux Mint 20 by executing the following command:<\/p>\n<pre><strong>bash MyFirstShellScript.sh<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"456\" height=\"25\" class=\"wp-image-3093\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-531.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-531.png 456w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-531-300x16.png 300w\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" \/><\/strong><\/p>\n<p>Executing this command will display the message that we have written in our shell script as shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"478\" height=\"61\" class=\"wp-image-3094\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-532.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-532.png 478w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-532-300x38.png 300w\" sizes=\"auto, (max-width: 478px) 100vw, 478px\" \/><\/p>\n<p>Alternatively, you can also execute the following command to run the very same shell script:<\/p>\n<pre><strong>sh MyFirstShellScript.sh<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"444\" height=\"23\" class=\"wp-image-3095\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-533.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-533.png 444w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-533-300x16.png 300w\" sizes=\"auto, (max-width: 444px) 100vw, 444px\" \/><\/strong><\/p>\n<p>The result of this command is shown in the image below. You can easily see that the output of this command and the one that we executed above is exactly the same.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"455\" height=\"60\" class=\"wp-image-3096\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-534.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-534.png 455w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-534-300x40.png 300w\" sizes=\"auto, (max-width: 455px) 100vw, 455px\" \/><\/p>\n<h2>Conclusion:<\/h2>\n<p>This tutorial presented to you the method of creating and running a shell script in Linux Mint 20 in the most simplified manner. So now, by following the very same procedure, you can even write and execute complex shell scripts in Linux Mint 20 very easily.<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction: A shell script is an alternative method of carrying out those operations automatically that have to be carried out quite frequently. Therefore, carrying them out manually is&hellip;<\/p>","protected":false},"author":3,"featured_media":3097,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[129,19],"class_list":["post-3086","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mint","tag-linux-mint-20","tag-shell-script"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/3086","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=3086"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/3086\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/3097"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=3086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=3086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=3086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}