{"id":14584,"date":"2022-02-01T08:51:44","date_gmt":"2022-02-01T08:51:44","guid":{"rendered":"https:\/\/linuxways.net\/?p=14584"},"modified":"2022-02-01T08:51:44","modified_gmt":"2022-02-01T08:51:44","slug":"how-to-run-sh-file-commands-all-in-once-in-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/how-to-run-sh-file-commands-all-in-once-in-linux\/","title":{"rendered":"How to Run .sh File Commands All in Once in Linux"},"content":{"rendered":"<p>In Linux distributions, the bash shell environment is the key element for managing the system components. Several commands are executed on the bash shell to perform a specific task. All bash commands are mostly stored in a bash script file with the \u2018.sh\u2019 extension. The .sh file is a shell script that is used to install an application or to perform various jobs in Linux \/ UNIX operating systems. The main benefit of writing the shell script is that you do not need to write different commands again on terminal windows.<\/p>\n<p>This tutorial will help you to create and run the .sh file or bash scripts using the terminal on the Linux system.<\/p>\n<h2>Run .sh file through the Terminal<\/h2>\n<p>In this method, you learn how to run sh file using the Terminal application.<\/p>\n<h3>Create .sh file in Linux<\/h3>\n<p>First, create a shell script file that we will run through the terminal. Open the text editor and add the following content to this file.<\/p>\n<pre><strong>echo \"Hello this is my first shell script.\"<\/strong><\/pre>\n<p>Save it with \u2018testscript.sh\u2019.<\/p>\n<h3>Make file executable<\/h3>\n<p>After creating the sh script file, it is important to set some executable permissions. Otherwise, you will receive an error of \u2018permission denied\u2019 on your screen.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"118\" class=\"wp-image-14585\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-701.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-701.png 724w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-701-300x49.png 300w\" sizes=\"auto, (max-width: 724px) 100vw, 724px\" \/><\/p>\n<p>To make this sh file executable use this command:<\/p>\n<pre>$ chmod +x filename.sh<\/pre>\n<p>Here, name of the file is \u2018testscript.sh\u2019.<\/p>\n<pre>$ chmod +x testscript.sh<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"105\" class=\"wp-image-14586\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-702.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-702.png 724w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-702-300x44.png 300w\" sizes=\"auto, (max-width: 724px) 100vw, 724px\" \/><\/p>\n<p>You can verify whether the required file is executable or not by executing the following command:<\/p>\n<pre>$ ls -l testscript.sh<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"721\" height=\"70\" class=\"wp-image-14587\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-703.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-703.png 721w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-703-300x29.png 300w\" sizes=\"auto, (max-width: 721px) 100vw, 721px\" \/><\/p>\n<p>This output will receive on the terminal that represents sh file as executable.<\/p>\n<h3>Run the sh file<\/h3>\n<p>Using the two different methods, you can run sh script using the terminal on a Linux system.<\/p>\n<p>The first method to run sh script is by calling the name of the file with its complete.<\/p>\n<pre>$ .\/testscript.sh<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"779\" height=\"76\" class=\"wp-image-14588\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-704.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-704.png 779w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-704-300x29.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-704-768x75.png 768w\" sizes=\"auto, (max-width: 779px) 100vw, 779px\" \/><\/p>\n<p>The alternative method to run sh file is by executing the bash command.<\/p>\n<pre>$ bash .\/testscript.sh<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"726\" height=\"76\" class=\"wp-image-14589\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-705.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-705.png 726w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-705-300x31.png 300w\" sizes=\"auto, (max-width: 726px) 100vw, 726px\" \/><\/p>\n<p>The current user with having sudo privileges can also run the sh file as:<\/p>\n<pre>$ sudo .\/testscript.sh<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"726\" height=\"79\" class=\"wp-image-14590\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-706.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-706.png 726w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-706-300x33.png 300w\" sizes=\"auto, (max-width: 726px) 100vw, 726px\" \/><\/p>\n<p>You can also debug the shell script by using the \u2018-x\u2019 option.<\/p>\n<pre>$ bash -x .\/testscript.sh<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"723\" height=\"74\" class=\"wp-image-14591\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-707.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-707.png 723w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-707-300x31.png 300w\" sizes=\"auto, (max-width: 723px) 100vw, 723px\" \/><\/p>\n<h2>Run the sh file using the Graphical interface<\/h2>\n<p>If you are using the GUI environment in Linux, you can also run sh file in the following steps:<\/p>\n<ol>\n<li>Select sh file that you want to open on your Linux system.<\/li>\n<li>Right-click on the file icon and choose \u2018Properties\u2019 from the drop-down list.<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1179\" height=\"553\" class=\"wp-image-14592\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-708.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-708.png 1179w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-708-300x141.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-708-1024x480.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-708-768x360.png 768w\" sizes=\"auto, (max-width: 1179px) 100vw, 1179px\" \/><\/p>\n<ol>\n<li>Now, go into the \u2018Permissions\u2019 tab and check the box \u2018Allow executing file as a program\u2019.<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"480\" height=\"480\" class=\"wp-image-14593\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-709.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-709.png 480w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-709-300x300.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-709-150x150.png 150w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/p>\n<ol>\n<li>Click on the file. You will select \u2018Run in Terminal\u2019 and you will notice it will be executed in the terminal.<\/li>\n<\/ol>\n<h2>Conclusion<\/h2>\n<p>We have seen how to run sh files using the terminal as well as using the command line or terminal. We explored various commands that are used for running sh files. Using the shell script, you can easily solve complex problems using a short script that also saves our time.<\/p>","protected":false},"excerpt":{"rendered":"<p>In Linux distributions, the bash shell environment is the key element for managing the system components. Several commands are executed on the bash shell to perform a specific&hellip;<\/p>","protected":false},"author":1,"featured_media":14669,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,5,83,165,2],"tags":[308,35,725],"class_list":["post-14584","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-debian","category-mint","category-opensuse","category-red-hat","category-ubuntu","tag-bash","tag-linux","tag-shell"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14584","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=14584"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14584\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/14669"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=14584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=14584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=14584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}