{"id":240883,"date":"2022-09-30T14:56:00","date_gmt":"2022-09-30T21:56:00","guid":{"rendered":"https:\/\/virtual-dba.com\/?p=240883"},"modified":"2024-03-21T11:27:20","modified_gmt":"2024-03-21T18:27:20","slug":"the-elements-of-a-bash-script","status":"publish","type":"post","link":"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/","title":{"rendered":"The Elements of a Bash Script"},"content":{"rendered":"\n<p>Database administrators need to know databases as well as the operating system (OS) their database is running on. Bash scripting is where the two merge. For the beginner, bash scripting can be intimidating, but all have the same basic structure: a beginning, middle, and end.<\/p>\n\n\n\n<p>Disclaimer: I am not a bash scripting expert. This blog will provide an elementary approach to bash scripts with some scripting and debugging tips. It is most beneficial for those with some knowledge in computer languages trying to get started interpreting and writing bash scripts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Beginning<\/h2>\n\n\n\n<p>This is the first line in the bash script where it lets the OS know that it is a bash script. The OS reads this line and knows the subsequent code should be run by the bash shell interpreter found in the \/bin directory.<\/p>\n\n\n\n<p>There are two ways to do this in a Unix-like OS, shown below. Each starts with a #!, often called sha-bang or hashbang. The first example is often used when the path of the bash interpreter is found in the user&#8217;s \/bin directory. The second example is used when the path of the bash interpreter is unknown.<\/p>\n\n\n<p><\/p>\n<pre><code># Used when the bash interpreter is in the user's \/bin directory\n#!\/bin\/bash \n\n# Used when the path to the bash interpreter is unknown\n#!\/usr\/bin\/env bash<\/code><\/pre>\n<p><\/p>\n\n\n<h2 class=\"wp-block-heading\">The Middle<\/h2>\n\n\n\n<p>The middle part is the bulkiest part of the bash script. This is where the executable commands go and the magic happens (when the script works) or doesn&#8217;t (when the script is not working).<\/p>\n\n\n\n<p>Scripts are as unique as the creator. Best practice is to use comments to help explain the code so anyone can understand it. Additionally, it is a good way to create an outline of steps when building a script. The example below is how I started a script that enabled the slow query log for 15 minutes, then disabled it.<\/p>\n\n\n<pre><code>#!\/bin\/bash\n\n# Set variables\n\n# Enable slow query log\n\n# Sleep for 15 minutes\n\n# Disable slow query log<\/code><\/pre>\n\n\n<p>Starting from scratch might be too ambitious for some beginners. It is common to take components from another script to make your own. Moreover, a lot can be learned from reverse engineering someone else&#8217;s script. The table below briefly describes components of a bash script to help you understand and identify them.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Components<\/td><td>Function<\/td><td>Syntax<\/td><\/tr><tr><td>Variables<\/td><td>Used to store data (numeric or string) to make a script more versatile.<\/td><td>2 ways to assign them:<br>declare &#8212; var=value<br>var=value<br><br>Evoking them:<br>$var<\/td><\/tr><tr><td>Functions<\/td><td>Values are passed into functions, usually through variables, to be executed with the commands inside the brackets.<\/td><td>2 ways to write them:<br>function function_name {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Command<br>}<br><br>function_name ( ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command&nbsp;<br>}<br><br>Evoking them:<br>function_name<\/td><\/tr><tr><td>Arrays<\/td><td>They store data like strings and integers. Arrays can hold more than one value.\u00a0\u00a0<br><br>There are 2 types of arrays:<br>Indexed: keys have ordered indexes starting with [0]<br><br>Associative: have key:value pairs<\/td><td>Creating indexed arrays:<br>declare -a arr<br>arr=(values)<br><br>Adding values to array:<br>arr[0]=first_value<br>arr[1]=second_value<br><br>Evoking values:<br>${arr[index]}<br><br>Creating associative arrays:<br>declare -A arr<br><br>Adding values to array:<br>arr[key]=value<br><br>Evoking values:<br>${arr[key]}<br><\/td><\/tr><tr><td>Boolean Operators<\/td><\/tr><tr><td>Or<\/td><td>Used to execute a command when one of two conditions need to be met to execute a command.<br><br>If the first condition isn&#8217;t met, the second condition must be true for the command to be run.<\/td><td><code>||<\/code><\/td><\/tr><tr><td>And<\/td><td>Used to execute a command when two conditions need to be met to execute a command.<br><br>If the first condition isn&#8217;t met, the command is not executed. If the first condition is met and the second one isn&#8217;t, the command is not executed.<\/td><td><code>&amp;&amp;<\/code><\/td><\/tr><tr><td>Conditional Statements<\/td><\/tr><tr><td>If<\/td><td>Used when a command should only be run if the specified test condition is met.\u00a0<br><br>Test condition often uses operators such as || and &amp;&amp;.<br><br>When brackets are used, the -gt(greater than) or\u00a0 -lt (less than) are used.\u00a0<br><br>When double parentheses are used, > or &lt; can be used instead.<\/td><td>2 ways to write them:<br>if [test_condition]; then&nbsp;<br>&nbsp;&nbsp;&nbsp;command<br>fi<br><br>if (( test_condition )); then&nbsp;<br>&nbsp;&nbsp;&nbsp;command<br>fi<br><\/td><\/tr><tr><td>if\/else<\/td><td>It&#8217;s an extension of the if statement. The else statement executes a command when the if statement returns false.<\/td><td>2 ways to write them:<br>if [test_condition]; then&nbsp;<br>&nbsp;&nbsp;&nbsp;command<br>else<br>&nbsp;&nbsp;&nbsp;command<br>fi<br><br>if (( test_condition )); then&nbsp;<br>&nbsp;&nbsp;&nbsp;command<br>else<br>&nbsp;&nbsp;&nbsp;command<br>fi<br><\/td><\/tr><tr><td>case<\/td><td>When there are multiple test conditions to be met to execute different commands, a case command can be used instead of a series of if\/else statements.<br><br>Test conditions usually use match operators like <code>=<\/code>, <code>||<\/code>, or <code>&amp;&amp;<\/code>.<\/td><td>case var in<br>test_condition)<br>&nbsp;&nbsp;&nbsp;command<br>;;<br>Another test_condition)<br>&nbsp;&nbsp;&nbsp;command<br>;;<br>Another test_condition)<br>&nbsp;&nbsp;&nbsp;command<br>;;<br>esac<br><\/td><\/tr><tr><td>Loops<\/td><\/tr><tr><td>while<\/td><td>Can be used with arrays or conditional statements. It will run commands while the test condition returns true.<\/td><td>while test_condition<br>do<br>&nbsp;&nbsp;command(s)<br>done<br><\/td><\/tr><tr><td>until<\/td><td>Similar to while loops but commands will run until the test condition returns true.<\/td><td>until test_condition<br>do<br>&nbsp;&nbsp;command(s)<br>done<br><\/td><\/tr><tr><td>for<\/td><td>Starts the value that is initiated <code>(i=value)<\/code> and will iterate up or down depending on the direction set by the executable (<code>i++<\/code> or <code>i--<\/code>) until the test condition is met. The variable used is i and incorporated into the command that is being executed.<\/td><td>for (( iniated_cal;&nbsp; test_condition; executable ));<br>do<br>&nbsp;&nbsp;command(s);<br>done<br><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The executable code might include any of the above components. The good thing is that other computer languages have these components and the principles are basically the same with some tweaking of the syntax. Variables and arrays, for instance, are often used in computer languages to hold data. Likewise, conditional statements and loops are used in computer languages like JavaScript. If these concepts are new, there are plenty of learning modules to explore as a beginner bash scripter. I did a bash script online course from Pluralsight, Shell Scripting with Bash and Z Shell.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The End<\/h2>\n\n\n\n<p>There is no official way to end a bash script. It might just end with the last executable command. The best practice is using an exit command that exits the script when the last command is successful (returns 0) .<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>exit 0<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Debugging<\/h2>\n\n\n\n<p>Before you start testing, you need to make sure that the script is executable. The below command can be used.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ chmod u+x &lt;filename&gt;<\/code><\/pre>\n\n\n\n<p>If the bash script is not working, adding -v or -x options to the she-bang line will print out every line as the script runs. It will give you an idea of where the code is breaking. I prefer the -x because it also prints the values of all the variables as well.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># will print every line before it runs\n#!\/bin\/bash -v \n\n# will print every line and the values in the script before it runs\n#!\/bin\/bash -x <\/code><\/pre>\n\n\n\n<p>If knowing where the code is breaking doesn&#8217;t help debugging it, there is also a command line utility, shellcheck, that automatically finds bugs in a bash script. If you do not want to install it, there is an online equivalent at <a href=\"https:\/\/www.shellcheck.net\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.shellcheck.net<\/a>. Sample output below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"982\" height=\"178\" src=\"https:\/\/virtual-dba.com\/wp-content\/uploads\/bash-scripting-shellcheck-output.png\" alt=\"Bash Scripting Shellcheck Output\" class=\"wp-image-240887\" srcset=\"https:\/\/virtual-dba.com\/wp-content\/uploads\/bash-scripting-shellcheck-output.png 982w, https:\/\/virtual-dba.com\/wp-content\/uploads\/bash-scripting-shellcheck-output-980x178.png 980w, https:\/\/virtual-dba.com\/wp-content\/uploads\/bash-scripting-shellcheck-output-480x87.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 982px, 100vw\" \/><\/figure>\n\n\n\n<p>And that&#8217;s it.<\/p>\n\n\n\n<p>As you can imagine, there is no one way to create a script. As a beginner, I started off really simple: no if\/else statements or loops. As my skills increased, I went back to a script and added more complexity. For example, below is a script that temporarily enables the slow query log in MySQL that I created from components of someone&#8217;s script (Senior DBA, Laura Nogaj) that I knew worked. I made changes, added commands, and tested it.<\/p>\n\n\n<pre><code>#!\/bin\/bash \n\n# Setting variables for default extra file\nmysqlUser='root'\nmysqlPW='password'\nmysqlHost='-999'\nmysqlSocket='-999'\nmysqlPort='-999'\n\n# Setting variables that will name files\nfileName=$HOSTNAME.bash_script_log.txt\ndefltsXtraFlNm=$HOSTNAME.bash.cnf\n\n# function removes files\nfunction func_rmFiles () {\nif test -f \"$1\"; then\n    rm -f $1\nfi\n}\n\n# function creates default extra file\nfunction func_creDfltsXtraFl () {\ntouch $1\nchmod 755 $1\ncat &lt;&lt; EOF &gt;&gt; $1\n[client]\nuser=$2\npassword=$3\nhost=$4\nsocket=$5\nport=$6\nEOF\n}\n\n# Creating default extra file\necho 'Creating defaults file' &gt;&gt; $fileName\n    func_creDfltsXtraFl $defltsXtraFlNm $mysqlUser $mysqlPW $mysqlHost $mysqlSocket $mysqlPort\n\n# Enabling slow query log\necho 'Enabling Slow Query Log' &gt;&gt; $fileName\n\techo `date +%m%d%Y` &gt;&gt; $fileName\n\techo `date +%T` &gt;&gt; $fileName\n\tmysql --defaults-extra-file=$defltsXtraFlNm -e \"set global slow_query_log = 1;\" \n\n# timer in minutes\nsleep 5m\n\n# Disable slow query log\necho 'Disabling Slow Query Log' &gt;&gt; $fileName\n\techo `date +%m%d%Y` &gt;&gt; $fileName\n\techo `date +%T` &gt;&gt; $fileName\n\tmysql --defaults-extra-file=$defltsXtraFlNm -e \"set global slow_query_log = 0;\" \n\necho 'Removed Script Files' &gt;&gt; $fileName\nfunc_rmFiles $defltsXtraFlNm\n    \nexit 0<\/code><\/pre>\n\n\n<p>The more you practice and challenge yourself, the more you learn and better your scripts become. Happy bash scripting!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Database administrators need to know databases as well as the operating system (OS) their database is running on. Bash scripting is where the two merge. For the beginner, bash scripting can be intimidating, but all have the same basic structure: a beginning, middle, and end. Disclaimer: I am not a bash scripting expert. This blog [&hellip;]<\/p>\n","protected":false},"author":49,"featured_media":240907,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","content-type":"","footnotes":""},"categories":[4166,39],"tags":[4192],"class_list":["post-240883","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","category-mysql","tag-bash-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.1 (Yoast SEO v27.1.1) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>The Elements of a Bash Script<\/title>\n<meta name=\"description\" content=\"Database administrators need to know what databases &amp; operating system (OS) their database is running on. Bash scripting is where the two merge, all with the same basic structure.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Elements of a Bash Script\" \/>\n<meta property=\"og:description\" content=\"Database administrators need to know what databases &amp; operating system (OS) their database is running on. Bash scripting is where the two merge, all with the same basic structure.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual-DBA Remote DBA Services &amp; Support - Certified Database Experts\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-30T21:56:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-21T18:27:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/virtual-dba.com\/wp-content\/uploads\/The-Elements-of-a-Bash-Script.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"557\" \/>\n\t<meta property=\"og:image:height\" content=\"291\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Monica Silva\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@virtual_dba\" \/>\n<meta name=\"twitter:site\" content=\"@virtual_dba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Monica Silva\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/\"},\"author\":{\"name\":\"Monica Silva\",\"@id\":\"https:\/\/virtual-dba.com\/#\/schema\/person\/9326f6340815aef31d91f56e4ba145da\"},\"headline\":\"The Elements of a Bash Script\",\"datePublished\":\"2022-09-30T21:56:00+00:00\",\"dateModified\":\"2024-03-21T18:27:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/\"},\"wordCount\":1229,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/virtual-dba.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/virtual-dba.com\/wp-content\/uploads\/The-Elements-of-a-Bash-Script.jpg\",\"keywords\":[\"Bash Scripting\"],\"articleSection\":[\"Blog\",\"MySQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/\",\"url\":\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/\",\"name\":\"The Elements of a Bash Script\",\"isPartOf\":{\"@id\":\"https:\/\/virtual-dba.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/virtual-dba.com\/wp-content\/uploads\/The-Elements-of-a-Bash-Script.jpg\",\"datePublished\":\"2022-09-30T21:56:00+00:00\",\"dateModified\":\"2024-03-21T18:27:20+00:00\",\"description\":\"Database administrators need to know what databases & operating system (OS) their database is running on. Bash scripting is where the two merge, all with the same basic structure.\",\"breadcrumb\":{\"@id\":\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#primaryimage\",\"url\":\"https:\/\/virtual-dba.com\/wp-content\/uploads\/The-Elements-of-a-Bash-Script.jpg\",\"contentUrl\":\"https:\/\/virtual-dba.com\/wp-content\/uploads\/The-Elements-of-a-Bash-Script.jpg\",\"width\":557,\"height\":291,\"caption\":\"The Elements of a Bash Script\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtual-dba.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The Elements of a Bash Script\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtual-dba.com\/#website\",\"url\":\"https:\/\/virtual-dba.com\/\",\"name\":\"Virtual-DBA Remote DBA Services &amp; Support - Certified Database Experts\",\"description\":\"Remote Database Administration\",\"publisher\":{\"@id\":\"https:\/\/virtual-dba.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtual-dba.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/virtual-dba.com\/#organization\",\"name\":\"Virtual-DBA: Remote DBA | Remote Database Administration\",\"alternateName\":\"Virtual-DBA powered by XTIVIA\",\"url\":\"https:\/\/virtual-dba.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtual-dba.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/virtual-dba.com\/wp-content\/uploads\/V-DBA-Database-Services-and-Support-Featured-Logo.jpg\",\"contentUrl\":\"https:\/\/virtual-dba.com\/wp-content\/uploads\/V-DBA-Database-Services-and-Support-Featured-Logo.jpg\",\"width\":557,\"height\":291,\"caption\":\"Virtual-DBA: Remote DBA | Remote Database Administration\"},\"image\":{\"@id\":\"https:\/\/virtual-dba.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/virtual_dba\",\"https:\/\/www.linkedin.com\/showcase\/36220649\/\",\"https:\/\/www.youtube.com\/channel\/UCx3AIeUQ2ziTLKZSJDZ-SEg\"],\"description\":\"Eliminate database downtime and spiraling costs with XTIVIA\u2019s Virtual-DBA. In today\u2019s always-on business world, gaps in 24x7 on-call DBA support, neglected maintenance and security, or a stretched team struggling with overwhelming workloads can lead to costly disruptions and threaten business continuity. XTIVIA\u2019s Virtual-DBA provides the immediate, expert database administration you need, exactly when you need it, ensuring optimal performance, ironclad security, and significant cost savings without the burden of expanding your in-house team. The goal of Virtual-DBA is to provide a cost-effective solution for organizations seeking to optimize the security, management, maintenance, availability, and performance of their critical business systems, whether self-managed or cloud-managed (e.g., AWS RDS, Azure SQL Database). We accomplish this through a comprehensive remote DBA service offering designed specifically to meet the Oracle\u00ae, DB2\u00ae, Informix\u00ae, MySQL\u2122, PostgreSQL\u00ae, MongoDB\u00ae, MariaDB, and Microsoft SQL Server\u00ae, CockroachDB, Databricks, AWS, and Azure needs of our clients.\",\"email\":\"info@xtivia.com\",\"telephone\":\"8886853101\",\"legalName\":\"XTIVIA, Inc\",\"foundingDate\":\"1992-05-01\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"201\",\"maxValue\":\"500\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtual-dba.com\/#\/schema\/person\/9326f6340815aef31d91f56e4ba145da\",\"name\":\"Monica Silva\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtual-dba.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9af003bf84c81e7a65a1816bc03fa96f866c8d4432b67dec463ef4fbcbe2d65d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9af003bf84c81e7a65a1816bc03fa96f866c8d4432b67dec463ef4fbcbe2d65d?s=96&d=mm&r=g\",\"caption\":\"Monica Silva\"},\"url\":\"https:\/\/virtual-dba.com\/author\/monica-silva\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"The Elements of a Bash Script","description":"Database administrators need to know what databases & operating system (OS) their database is running on. Bash scripting is where the two merge, all with the same basic structure.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/","og_locale":"en_US","og_type":"article","og_title":"The Elements of a Bash Script","og_description":"Database administrators need to know what databases & operating system (OS) their database is running on. Bash scripting is where the two merge, all with the same basic structure.","og_url":"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/","og_site_name":"Virtual-DBA Remote DBA Services &amp; Support - Certified Database Experts","article_published_time":"2022-09-30T21:56:00+00:00","article_modified_time":"2024-03-21T18:27:20+00:00","og_image":[{"width":557,"height":291,"url":"https:\/\/virtual-dba.com\/wp-content\/uploads\/The-Elements-of-a-Bash-Script.jpg","type":"image\/jpeg"}],"author":"Monica Silva","twitter_card":"summary_large_image","twitter_creator":"@virtual_dba","twitter_site":"@virtual_dba","twitter_misc":{"Written by":"Monica Silva","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#article","isPartOf":{"@id":"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/"},"author":{"name":"Monica Silva","@id":"https:\/\/virtual-dba.com\/#\/schema\/person\/9326f6340815aef31d91f56e4ba145da"},"headline":"The Elements of a Bash Script","datePublished":"2022-09-30T21:56:00+00:00","dateModified":"2024-03-21T18:27:20+00:00","mainEntityOfPage":{"@id":"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/"},"wordCount":1229,"commentCount":0,"publisher":{"@id":"https:\/\/virtual-dba.com\/#organization"},"image":{"@id":"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#primaryimage"},"thumbnailUrl":"https:\/\/virtual-dba.com\/wp-content\/uploads\/The-Elements-of-a-Bash-Script.jpg","keywords":["Bash Scripting"],"articleSection":["Blog","MySQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/","url":"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/","name":"The Elements of a Bash Script","isPartOf":{"@id":"https:\/\/virtual-dba.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#primaryimage"},"image":{"@id":"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#primaryimage"},"thumbnailUrl":"https:\/\/virtual-dba.com\/wp-content\/uploads\/The-Elements-of-a-Bash-Script.jpg","datePublished":"2022-09-30T21:56:00+00:00","dateModified":"2024-03-21T18:27:20+00:00","description":"Database administrators need to know what databases & operating system (OS) their database is running on. Bash scripting is where the two merge, all with the same basic structure.","breadcrumb":{"@id":"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#primaryimage","url":"https:\/\/virtual-dba.com\/wp-content\/uploads\/The-Elements-of-a-Bash-Script.jpg","contentUrl":"https:\/\/virtual-dba.com\/wp-content\/uploads\/The-Elements-of-a-Bash-Script.jpg","width":557,"height":291,"caption":"The Elements of a Bash Script"},{"@type":"BreadcrumbList","@id":"https:\/\/virtual-dba.com\/blog\/the-elements-of-a-bash-script\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtual-dba.com\/"},{"@type":"ListItem","position":2,"name":"The Elements of a Bash Script"}]},{"@type":"WebSite","@id":"https:\/\/virtual-dba.com\/#website","url":"https:\/\/virtual-dba.com\/","name":"Virtual-DBA Remote DBA Services &amp; Support - Certified Database Experts","description":"Remote Database Administration","publisher":{"@id":"https:\/\/virtual-dba.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtual-dba.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/virtual-dba.com\/#organization","name":"Virtual-DBA: Remote DBA | Remote Database Administration","alternateName":"Virtual-DBA powered by XTIVIA","url":"https:\/\/virtual-dba.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtual-dba.com\/#\/schema\/logo\/image\/","url":"https:\/\/virtual-dba.com\/wp-content\/uploads\/V-DBA-Database-Services-and-Support-Featured-Logo.jpg","contentUrl":"https:\/\/virtual-dba.com\/wp-content\/uploads\/V-DBA-Database-Services-and-Support-Featured-Logo.jpg","width":557,"height":291,"caption":"Virtual-DBA: Remote DBA | Remote Database Administration"},"image":{"@id":"https:\/\/virtual-dba.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/virtual_dba","https:\/\/www.linkedin.com\/showcase\/36220649\/","https:\/\/www.youtube.com\/channel\/UCx3AIeUQ2ziTLKZSJDZ-SEg"],"description":"Eliminate database downtime and spiraling costs with XTIVIA\u2019s Virtual-DBA. In today\u2019s always-on business world, gaps in 24x7 on-call DBA support, neglected maintenance and security, or a stretched team struggling with overwhelming workloads can lead to costly disruptions and threaten business continuity. XTIVIA\u2019s Virtual-DBA provides the immediate, expert database administration you need, exactly when you need it, ensuring optimal performance, ironclad security, and significant cost savings without the burden of expanding your in-house team. The goal of Virtual-DBA is to provide a cost-effective solution for organizations seeking to optimize the security, management, maintenance, availability, and performance of their critical business systems, whether self-managed or cloud-managed (e.g., AWS RDS, Azure SQL Database). We accomplish this through a comprehensive remote DBA service offering designed specifically to meet the Oracle\u00ae, DB2\u00ae, Informix\u00ae, MySQL\u2122, PostgreSQL\u00ae, MongoDB\u00ae, MariaDB, and Microsoft SQL Server\u00ae, CockroachDB, Databricks, AWS, and Azure needs of our clients.","email":"info@xtivia.com","telephone":"8886853101","legalName":"XTIVIA, Inc","foundingDate":"1992-05-01","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"201","maxValue":"500"}},{"@type":"Person","@id":"https:\/\/virtual-dba.com\/#\/schema\/person\/9326f6340815aef31d91f56e4ba145da","name":"Monica Silva","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtual-dba.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9af003bf84c81e7a65a1816bc03fa96f866c8d4432b67dec463ef4fbcbe2d65d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9af003bf84c81e7a65a1816bc03fa96f866c8d4432b67dec463ef4fbcbe2d65d?s=96&d=mm&r=g","caption":"Monica Silva"},"url":"https:\/\/virtual-dba.com\/author\/monica-silva\/"}]}},"_links":{"self":[{"href":"https:\/\/virtual-dba.com\/wp-json\/wp\/v2\/posts\/240883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtual-dba.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtual-dba.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtual-dba.com\/wp-json\/wp\/v2\/users\/49"}],"replies":[{"embeddable":true,"href":"https:\/\/virtual-dba.com\/wp-json\/wp\/v2\/comments?post=240883"}],"version-history":[{"count":0,"href":"https:\/\/virtual-dba.com\/wp-json\/wp\/v2\/posts\/240883\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/virtual-dba.com\/wp-json\/wp\/v2\/media\/240907"}],"wp:attachment":[{"href":"https:\/\/virtual-dba.com\/wp-json\/wp\/v2\/media?parent=240883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtual-dba.com\/wp-json\/wp\/v2\/categories?post=240883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtual-dba.com\/wp-json\/wp\/v2\/tags?post=240883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}