{"id":5959,"date":"2024-05-30T07:53:02","date_gmt":"2024-05-30T07:53:02","guid":{"rendered":"https:\/\/natsav.com\/blog\/?p=5959"},"modified":"2024-05-30T12:10:32","modified_gmt":"2024-05-30T12:10:32","slug":"write-scripting-in-centos-7","status":"publish","type":"post","link":"https:\/\/natsav.com\/blog\/write-scripting-in-centos-7\/","title":{"rendered":"How to Write Scripting in Centos 7"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_68_1 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/natsav.com\/blog\/write-scripting-in-centos-7\/#What_is_Shell\" title=\"What is Shell?\">What is Shell?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/natsav.com\/blog\/write-scripting-in-centos-7\/#Types_of_Shell\" title=\"Types of Shell\">Types of Shell<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"What_is_Shell\"><\/span><strong>What is Shell?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Shell is a UNIX term for an interface between a user and an operating system service. Shell provides users with an interface and accepts human-readable commands into the system and executes those commands which can run automatically and give the program\u2019s output in a shell script.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Types_of_Shell\"><\/span><strong>Types of Shell<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"color: #333333;\">There are two main shells in Linux:<\/span><\/p>\n<p><strong>1. The Bourne Shell:<\/strong> The prompt for this shell is $ and its derivatives are listed below:<\/p>\n<p>POSIX shell also is known as sh<br \/>\nKorn Shell also knew as sh<br \/>\nBourne Again SHell also knew as bash (most popular)<\/p>\n<p><strong>2. The C shell:<\/strong> The prompt for this shell is %, and its subcategories are:<\/p>\n<p>C shell also is known as csh<br \/>\nTops C shell also is known as tcsh<\/p>\n<p>To write scripting in CentOS 7, you can use any text editor available in CentOS 7 such as Vi, Vim, Nano, or Emacs. These editors are installed by default in CentOS 7. Here&#8217;s a step-by-step guide to creating and writing a simple shell script:<\/p>\n<p><strong><u>Step 1<\/u><\/strong>:- Open a terminal in <a href=\"https:\/\/natsav.com\/linux-vps-server-hosting.php\">CentOS 7<\/a>.<\/p>\n<p><strong><u>Step 2<\/u><\/strong>:- Choose a text editor. For example, to use Nano, you can type.<\/p>\n<p># [nano myscript.sh]<br \/>\nReplace myscript.sh with the desired name for your script.<\/p>\n<p><strong><u>Step 3<\/u><\/strong>:- This will open the Nano text editor. Now, you can write your script. For example:<\/p>\n<p>#! \/bin\/bash<br \/>\n# This is a simple script<br \/>\n# [echo &#8220;Hello, CentOS 7!&#8221;]<\/p>\n<p>In this example, #!\/bin\/bash is called a shebang, which tells the system to execute the script using the Bash shell. The echo command is used to print &#8220;Hello, CentOS 7!&#8221; to the terminal.<\/p>\n<p><strong><u>Step 4<\/u><\/strong>:- Once you have finished writing your script, you can save it by pressing<br \/>\n&#8216;Ctrl + O&#8217; to write out the file, then press Enter. To exit Nano, press &#8216;Ctrl + X&#8217;.<\/p>\n<p><strong><u>Step 5<\/u><\/strong>:- Make the script executable by running the following command:<\/p>\n<p># [chmod +x myscript.sh]<br \/>\nThis command gives execute permission to the script.<\/p>\n<p><strong><u>Step 6<\/u><\/strong>:- Finally, to run the script, type:<br \/>\n# [.\/myscript.sh]<br \/>\nReplace myscript.sh with the name of your script if it&#8217;s different.<\/p>\n<p>Please feel free to reach out to us for top-quality hosting products, such as Web Hosting, cPanel Hosting, Cyberpanel Hosting, Cloud VPS, <a href=\"https:\/\/natsav.com\/dedicated-server-hosting.php\"><strong>Dedicated Servers in India<\/strong><\/a>, Email Hosting, Backup Solutions, Windows Server, and Linux Server. We are here to assist you with all your hosting needs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Shell? Shell is a UNIX term for an interface between a user and an operating system service. Shell provides users with an interface and accepts human-readable commands into the system and executes those commands which can run automatically and give the program\u2019s output in a shell script. Types of Shell There are two [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5960,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[256],"tags":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/03\/Centos-7-e1712814874398.png?fit=860%2C385&ssl=1","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5959"}],"collection":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/comments?post=5959"}],"version-history":[{"count":7,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5959\/revisions"}],"predecessor-version":[{"id":5962,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5959\/revisions\/5962"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/media\/5960"}],"wp:attachment":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/media?parent=5959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/categories?post=5959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/tags?post=5959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}