{"id":21667,"date":"2023-09-30T16:23:07","date_gmt":"2023-09-30T16:23:07","guid":{"rendered":"https:\/\/linuxways.net\/?p=21667"},"modified":"2023-09-30T16:23:07","modified_gmt":"2023-09-30T16:23:07","slug":"how-to-run-the-sh-file-shell-script-in-linux-ubuntu","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/linux-commands\/how-to-run-the-sh-file-shell-script-in-linux-ubuntu\/","title":{"rendered":"How To Run the .sh File Shell Script In Linux \/ Ubuntu?"},"content":{"rendered":"<p>The \u201c.sh\u201d Shell Script Files are scripting files that contain scripting language commands ready to be executed and run by the Ubuntu Shell. These are text files that contain programming language code that may be used to carry out automated tasks or create programs or applications.<\/p>\n<p>This article explains the process to run the \u201c.sh\u201d Shell Script Files in Ubuntu.<\/p>\n<h2><strong>How To Run the .sh File Shell Script In Linux \/ Ubuntu?<\/strong><\/h2>\n<p>The \u201c.sh\u201d Script File in Ubuntu can be executed using the Command Line, i.e. Terminal. The \u201c.sh\u201d Script Files can run in the Terminal using either the \u201csh\u201d command or the shortcut method using the \u201c.\/\u201d line with the script file. Both the methods are explained below.<\/p>\n<h2><strong>Run the .sh File Script in Ubuntu using the \u201csh\u201d Command<\/strong><\/h2>\n<p>To run the Script file in Ubuntu, ensure it is executable before using the \u201csh\u201d command. To confirm the executable file, use the command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span> <span class=\"sy0\">&lt;<\/span>fileName.sh<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>This will return the permissions of the file. In our case, we have a \u201cscriptFile.sh\u201d Script File:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1663\" height=\"193\" class=\"wp-image-21668\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-1.png 1663w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-1-300x35.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-1-1024x119.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-1-768x89.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-1-1536x178.png 1536w\" sizes=\"auto, (max-width: 1663px) 100vw, 1663px\" \/><\/p>\n<p>To check the permission, the command used will be:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span> scriptFile.sh<\/div><\/div>\n<p>The \u201c-rwxrwx\u201d confirms the Script File has the Read, Write and Execute Permissions:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"734\" height=\"182\" class=\"wp-image-21669\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-2.png 734w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-2-300x74.png 300w\" sizes=\"auto, (max-width: 734px) 100vw, 734px\" \/><\/p>\n<p>Now to execute and run the Script File, the command \u201csh\u201d will be used:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">sh<\/span> <span class=\"sy0\">&lt;<\/span>fileName<span class=\"sy0\">&gt;<\/span>.sh<\/div><\/div>\n<p>In our case, the file name is \u201cscriptFile.sh\u201d, so the command to run our Script File will be:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">sh<\/span> scriptFile.sh<\/div><\/div>\n<p>This will run the script file and the output of executed script can be seen in the terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"733\" height=\"97\" class=\"wp-image-21670\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-3.png 733w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-3-300x40.png 300w\" sizes=\"auto, (max-width: 733px) 100vw, 733px\" \/><\/p>\n<p>The \u201cHello World!\u201d output in the terminal confirms the Script was executed using the \u201csh\u201d command in Ubuntu.<\/p>\n<p>The \u201c-v\u201d flag can also be used with the \u201csh\u201d command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">sh<\/span> <span class=\"re5\">-v<\/span> scriptFile.sh<\/div><\/div>\n<p>It will return the script inside the file as well as the output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"121\" class=\"wp-image-21671\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-4.png 720w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-4-300x50.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/p>\n<h3><strong>Run the .sh File Script in Ubuntu using the \u201c.\/\u201d Shortcut<\/strong><\/h3>\n<p>The shortcut method directly runs the \u201c.sh\u201d Script file in Ubuntu using the \u201c<strong>.\/<\/strong>\u201d following the file name. The syntax to use the shortcut method is:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">.<span class=\"sy0\">\/&lt;<\/span>fileName<span class=\"sy0\">&gt;<\/span>.sh<\/div><\/div>\n<p>Before executing the Command, ensure the directory contains the Script File. In our case, to execute and run the \u201cscriptFile.sh\u201d Script File in Ubuntu, the command used will be:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">.<span class=\"sy0\">\/<\/span>scriptFile.sh<\/div><\/div>\n<p>The script file will be executed directly in the terminal of Ubuntu:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"868\" height=\"348\" class=\"wp-image-21672\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-5.png 868w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-5-300x120.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21667-5-768x308.png 768w\" sizes=\"auto, (max-width: 868px) 100vw, 868px\" \/><\/p>\n<p>The script file runs and the output \u201cHello World!\u201d is displayed in the terminal. This is how you can directly run script files from the terminal.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>The \u201csh\u201d command and the \u201c.\/\u201d shortcut method both are useful ways to execute the \u201c.sh\u201d File Shell Script in Ubuntu. The \u201csh\u201d command can also be used to display the input lines of the script file using the \u201c-v\u201d flag whereas the \u201c.\/\u201d command directly runs the script without any command when working in the same directory. This article explained both methods to run the \u201c.sh\u201d Shell Script Files in Ubuntu.<\/p>","protected":false},"excerpt":{"rendered":"<p>The \u201csh\u201d command and the \u201c.\/\u201d shortcut method both are useful ways to execute the \u201c.sh\u201d Script Files in Ubuntu with \u201csh\u201d also displaying the script input lines.<\/p>","protected":false},"author":110,"featured_media":21673,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049],"tags":[],"class_list":["post-21667","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/21667","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\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=21667"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/21667\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/21673"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=21667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=21667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=21667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}