
{"id":7002,"date":"2022-01-11T10:58:08","date_gmt":"2022-01-11T10:58:08","guid":{"rendered":"https:\/\/rax-stg-wp-aws.com\/blogs\/unlocking-the-power-of-shell-scripting-a-beginners-guide\/"},"modified":"2026-11-03T19:27:37","modified_gmt":"2026-11-03T19:27:37","slug":"unlocking-the-power-of-shell-scripting-a-beginners-guide","status":"publish","type":"blogs","link":"https:\/\/www.rackspace.com\/en-gb\/blogs\/unlocking-the-power-of-shell-scripting-a-beginners-guide\/","title":{"rendered":"Unlocking the Power of Shell Scripting: A Beginner&#8217;s Guide"},"content":{"rendered":"<h3>What is shell script?<\/h3>\n<p>Shell script is basically a computer program which divided into two parts:<\/p>\n<ul>\n<li>Shell is an Interpreter which converts low level &amp; high level language in to machine language for Unix based Operating systems .<\/li>\n<li>Script stands for Set of Commands.<\/li>\n<\/ul>\n<h3>What Types of Shells are Supported Shell in Linux?<\/h3>\n<p>Below (snapshot) are the few examples of shells supported by Linux 6. It may vary from version to version.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26061-body-technical-blog-basics-shell-script-image-1.png\" alt=\"technical-blog-basics-shell-script-image-1\" \/><\/p>\n<h3>How to write as a shell script?<\/h3>\n<p><code>#!\/bin\/bash \u2013<\/code>&nbsp;This is known as header or shebang of a script.<br \/>\n<code>\u2022 #! <\/code>&nbsp;&#8211; Is a symbol which is called the interpreter.<\/p>\n<p>\u2022 #Commented line \u2013 Only readable format shows what script is executing \/bin\/bash is the location of shell &amp; shell we are using is bash .<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26061-body-technical-blog-basics-shell-script-image-2.png\" alt=\"technical-blog-basics-shell-script-image-2\" \/><\/p>\n<p><em>For example.<\/em><\/p>\n<p>Here we have created a script in bash shell &amp; executed using sh.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26061-body-technical-blog-basics-shell-script-image-3.png\" alt=\"technical-blog-basics-shell-script-image-3\" \/><\/p>\n<h3>What are variables in shell scripting?<\/h3>\n<p>Variables store any values which can be called during the execution of a script.<\/p>\n<h3>What are the Types of variables? There are two types of variables.<\/h3>\n<p><strong>System defined Variable (SDV)<\/strong> &#8211; These are predefined &amp; maintained by Linux only. SDV will always show in Capital letters.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26061-body-technical-blog-basics-shell-script-image-4.png\" alt=\"technical-blog-basics-shell-script-image-4\" \/><\/p>\n<p><strong>User defined Variable (UDV)<\/strong> \u2013 These can be created &amp; maintained by user. UDV should always define in Small letters<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26061-body-technical-blog-basics-shell-script-image-5.png\" alt=\"technical-blog-basics-shell-script-image-5\" \/><\/p>\n<h3>What are special variables?<\/h3>\n<p>\u2022 $0 &#8211; Check current script name<\/p>\n<p>\u2022 $n &#8211; Sequence of arguments<\/p>\n<p>\u2022 $# &#8211; To check count (number of arguments) in script.<\/p>\n<p>\u2022 $* &#8211; It stores complete set of positional parameter in a single string<\/p>\n<p>\u2022 $@ &#8211; Quoted string treated as separate arguments.<\/p>\n<p>\u2022 $? &#8211; exit status of command<\/p>\n<p>\u2022 $$ &#8211; Check PID of current shell.<\/p>\n<p>\u2022 $! &#8211; check PID of last background Job<\/p>\n<p>Below is an example.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26061-body-technical-blog-basics-shell-script-image-6.png\" alt=\"technical-blog-basics-shell-script-image-6\" \/><\/p>\n<p>Output:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26061-body-technical-blog-basics-shell-script-image-7.png\" alt=\"technical-blog-basics-shell-script-image-7\" \/><\/p>\n<h3>Arithmetic Operators&nbsp;<\/h3>\n<p>These operators are used for arithmetic calculations .<\/p>\n<p>Below is an example:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26061-body-technical-blog-basics-shell-script-image-8.png\" alt=\"technical-blog-basics-shell-script-image-8\" \/><\/p>\n<p>Output:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26061-body-technical-blog-basics-shell-script-image-9.png\" alt=\"technical-blog-basics-shell-script-image-9\" \/><\/p>\n<h3>Functions and Arguments&nbsp;<\/h3>\n<p>A function is a group of commands which can be used as a single handle. To execute this set of commands, call the function by the name provided.<\/p>\n<p>Below is an example of single function. We have created a shell script using a single function &amp; called the function in script at very last.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26061-body-technical-blog-basics-shell-script-image-10.png\" alt=\"technical-blog-basics-shell-script-image-10\" \/><\/p>\n<p>Output<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26061-body-technical-blog-basics-shell-script-image-11.png\" alt=\"technical-blog-basics-shell-script-image-11\" \/><\/p>\n<p><em>Below is an example of two functions.<\/em><\/p>\n<p>Below we have created shell script calling two different functions. Output of script depends upon the calling sequence of functions.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26061-body-technical-blog-basics-shell-script-image-12.png\" alt=\"technical-blog-basics-shell-script-image-12\" \/><\/p>\n<p>Output:<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26061-body-technical-blog-basics-shell-script-image-13.png\" alt=\"technical-blog-basics-shell-script-image-13\" \/><\/p>\n<h3>Conclusion&nbsp;<\/h3>\n<p>Shell scripting can be used to automate manual tasks. It is very useful for most repetitive tasks which are time consuming to execute or schedule using one line at a time<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understanding the Fundamentals of Shell Scripting<\/p>\n","protected":false},"author":2,"featured_media":7004,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","format":"standard","meta":{"content-type":"","nid":"26061","content_type":"blog","created_by":"11255","authored_on":"2023-09-20T09:58:07+00:00","field_article_industries":"","tag_category":"Technical","field_blog_author_text":"by Rackspace Technology Staff","seo_description":"Unveil the fundamentals of shell scripting with Rackspace Technology. Learn how shell scripting automates tasks and simplifies IT operations.","field_featured_image":"","insights_image":"\/wp-content\/uploads\/2026\/blog_technical_images\/26061-insights_image-multi-cloud-technical-blog-1-insights.jpg","field_partners":"","rxt_platforms":"Cloud","product":"","publisheddate":"2022-01-11T10:58:08","rxt_solutions":"","opengraph_tag":"","x_tag":"","teaser_flag":"Technical Blog","seo_titile":"Shell Scripting: Fundamentals Explained | Rackspace","field_topics":"","field_slug":"Fundamentals Shell Scripting","footnotes":""},"categories":[178],"tags":[204],"class_list":["post-7002","blogs","type-blogs","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-technical"],"_links":{"self":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs"}],"about":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/types\/blogs"}],"author":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/comments?post=7002"}],"version-history":[{"count":2,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7002\/revisions"}],"predecessor-version":[{"id":8727,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7002\/revisions\/8727"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/media\/7004"}],"wp:attachment":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/media?parent=7002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/categories?post=7002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/tags?post=7002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}