{"id":33968,"date":"2020-09-07T11:32:53","date_gmt":"2020-09-07T16:32:53","guid":{"rendered":"https:\/\/www.rosehosting.com\/blog\/?p=33968"},"modified":"2022-06-03T03:32:42","modified_gmt":"2022-06-03T08:32:42","slug":"bash-script-examples","status":"publish","type":"post","link":"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/","title":{"rendered":"Bash Script Examples"},"content":{"rendered":"<div id=\"bsf_rt_marker\"><\/div>\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"742\" height=\"372\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2020\/08\/bash-script-examples.jpg\" alt=\"\" class=\"wp-image-34169\" srcset=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2020\/08\/bash-script-examples.jpg 742w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2020\/08\/bash-script-examples-300x150.jpg 300w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2020\/08\/bash-script-examples-150x75.jpg 150w\" sizes=\"(max-width: 742px) 100vw, 742px\" \/><\/figure><\/div>\n\n\n\n<p>In this tutorial, we will explain the most common bash operations while also showing you a few bash script examples.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignright size-large\"><img decoding=\"async\" width=\"115\" height=\"115\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2020\/08\/bash-script-how-to-with-examples-linux.jpg\" alt=\"\" class=\"wp-image-34170\"\/><\/figure><\/div>\n\n\n\n<p>A Unix shell program interprets instructions and programs in the form of commands. These commands are either directly entered by the user, or they can be run in sequence from a file (called a shell script). An important distinction of bash scripts when compared to other coding languages is that they are <strong>interpreted<\/strong> and <strong>not compiled<\/strong>. When you write a shell script and then run it, it&#8217;s interpreted by your operating system, with no compilation required. <\/p>\n\n\n\n<p>Bash scripts are a versatile and handy tool that most system administrators love using to simplify their workflow and automate repetitive tasks. With scripts, you can do almost anything that you can do using a normal shell environment.<\/p>\n\n\n\n<!--more-->\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69d2702c9f6c8\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><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><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69d2702c9f6c8\"  aria-label=\"Toggle\" \/><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:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#Requirements\" >Requirements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#1-The-echo-Command-in-Scripts\" >1. The echo Command in Scripts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#2-Get-User-Input-in-a-Bash-Script\" >2. Get User Input in a Bash Script<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#3-If-Statements-in-Bash-Scripts\" >3. If Statements in Bash Scripts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#4-If-Statements-with-AND-logic-in-Bash\" >4. If Statements with AND logic in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#5-If-Statements-with-OR-logic-in-Bash\" >5. If Statements with OR logic in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#6-If-Else-Statements-in-Bash\" >6. If-Else Statements in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#7-While-Loops-in-Bash\" >7. While Loops in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#8-For-Loop-in-Bash\" >8. For Loop in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#9-Read-from-a-File-in-Bash\" >9. Read from a File in Bash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#10-Check-If-a-File-or-Directory-Exists\" >10. Check If a File or Directory Exists<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-requirements\"><span class=\"ez-toc-section\" id=\"Requirements\"><\/span>Requirements<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>A Linux VPS with root access enabled or a user with sudo privileges. All common distributions of Linux (Debian, Ubuntu, CentOS, Fedora, etc) are all able to run shell scripts.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-1-the-echo-command-in-scripts\"><span class=\"ez-toc-section\" id=\"1-The-echo-Command-in-Scripts\"><\/span>1. The echo Command in Scripts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can run a bash script from the terminal, or by executing it from a bash file that is saved on your computer or server.<\/p>\n\n\n\n<p>Let&#8217;s write our first bash script example by creating a simple shell script file named <code>test.sh<\/code> that prints the line &#8220;Hello World&#8221;:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano test.sh<\/pre>\n\n\n\n<p>The <code>.sh<\/code> extension is short for <code>shell<\/code>. Continue by adding the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\necho \"Hello World\"<\/pre>\n\n\n\n<p>To save, press Ctrl+O and then press enter to confirm the filename. Then press Ctrl+X to exit the nano text editor.<\/p>\n\n\n\n<p>Once you have done the above, run the bash script using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash test.sh<\/pre>\n\n\n\n<p>This will print the following output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Hello World<\/pre>\n\n\n\n<p>This is a very simple command, however, it can be useful when debugging your script or when you want to display some information to the user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-2-get-user-input-in-a-bash-script\"><span class=\"ez-toc-section\" id=\"2-Get-User-Input-in-a-Bash-Script\"><\/span>2. Get User Input in a Bash Script<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can accept input from the keyboard and assign a value to a user-defined shell variable using the read command. This will read whatever is entered by the keyboard and save it to the variable.<\/p>\n\n\n\n<p>To start, create a new bash script named <code>input.sh<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano input.sh<\/pre>\n\n\n\n<p>Add the following lines. These commands will display a question, take input from the user, and print the value entered while also combining it with a string.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\necho \"What is Your Name?\"\nread name\necho \"My Name is $name\"<\/pre>\n\n\n\n<p>Save and close the file, then run the script using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash input.sh<\/pre>\n\n\n\n<p>You will be asked to provide your name and print the message with other string as shown below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">What is Your Name?\nJohn\nMy Name is John<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-3-if-statements-in-bash-scripts\"><span class=\"ez-toc-section\" id=\"3-If-Statements-in-Bash-Scripts\"><\/span>3. If Statements in Bash Scripts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Bash if statements are very useful and allow us to make decisions in bash scripts. With if statements, you can decide whether or not to run a block of code based on a preset condition being met or not.<\/p>\n\n\n\n<p>The basic syntax of if statement is shown below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">if [condition]; then\n\nfi<\/pre>\n\n\n\n<p>Anything between the keywords <code>then<\/code> and <code>fi<\/code> will be executed only if the condition is true.<\/p>\n\n\n\n<p>For better understanding, create a <code>test-if.sh<\/code> file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano test-if.sh<\/pre>\n\n\n\n<p>Here, the number 8 is assigned to the variable <code>n<\/code>. If the value of <code>$n<\/code> is less than 10, then the output will be &#8220;one-digit number&#8221;, otherwise the output will be a &#8220;two-digit number&#8221;. Note that there is no upper limit to the range, so even three-digit numbers will give &#8220;two digit number&#8221; as the output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\nn=9\nif [ $n -lt 10 ];\nthen\necho \"one digit number\"\nelse\necho \"two digit number\"\nfi<\/pre>\n\n\n\n<p>The <code>-lt<\/code> operator is a comparison tool. LT is short for &#8220;less than&#8221;. You can replace it and use <code>-gt<\/code> to check whether <code>n<\/code> is &#8220;greater than&#8221; the value on the right.<\/p>\n\n\n\n<p>Save and close the file, then run the bash script example with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash test-if.sh<\/pre>\n\n\n\n<p>You should see the following output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">one digit number<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-4-if-statements-with-and-logic-in-bash\"><span class=\"ez-toc-section\" id=\"4-If-Statements-with-AND-logic-in-Bash\"><\/span>4. If Statements with AND logic in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you want to check for multiple conditions in a bash script, then you can use logic gates to accomplish this. The AND logic gate only returns TRUE when <strong>both<\/strong> comparisons being made are TRUE. AND logic can be defined using the symbol <code>&amp;&amp;<\/code>.<\/p>\n\n\n\n<p>Create a new <code>test-and.sh<\/code> file where we can test this AND logic:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano test-and.sh<\/pre>\n\n\n\n<p>Add the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo \"Enter your name\"\nread name\necho \"Enter your age\"\nread age\nif [[ ( $name == \"john\" &amp;&amp; $age == \"40\" ) ]]; then\necho \"you are right\"\nelse\necho \"you are wrong\"\nfi<\/pre>\n\n\n\n<p>Save and close the file, then run the newly-written script with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash test-and.sh<\/pre>\n\n\n\n<p>This will ask for your name and age, and then compare it with AND logic. If both of the variables match the values that they are being compared to, then the output will be &#8220;you are right&#8221; &#8211; otherwise, the output will be &#8220;you are wrong&#8221;. <strong>Both<\/strong> values must be identical to the variables in order for the if statement to succeed.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Enter your name\njohn\nEnter your age\n40\nyou are right<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-5-if-statements-with-or-logic-in-bash\"><span class=\"ez-toc-section\" id=\"5-If-Statements-with-OR-logic-in-Bash\"><\/span>5. If Statements with OR logic in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The OR condition is also frequently used in bash scripts if you want to check for multiple conditions being met individually. An OR gate returns a TRUE value when <strong>one of any<\/strong> required conditions is met.<\/p>\n\n\n\n<p>For example, create a <code>test-or.sh<\/code> script with the following contents:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano test-or.sh<\/pre>\n\n\n\n<p>Add the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\necho \"Enter any number between 1 and 99 which can be divided by 10\"\nread number\nif [[ ( $number -eq 10 || $number  -eq 20 || $number -eq 30 || $number -eq 40 || $number -eq 50 || $number -eq 60 || $number -eq 70 || $number -eq 80 || $number -eq 90 ) ]]\nthen\necho \"You are right\"\nelse\necho \"You are wrong\"\nfi<\/pre>\n\n\n\n<p>Save and close the file before running the script with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash test-or.sh<\/pre>\n\n\n\n<p>This script will ask the user to enter any number between 1 and 99 that can be divided by 10. If the value is a number that can be divided by 10 (e.g. 10 or 20), then the output will be &#8220;You are right&#8221; &#8211; otherwise, the output will be &#8220;You are wrong&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Enter any number between 1 and 99 which can be divided by 10\n31\nYou are wrong<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">Enter any number between 1 and 99 which can be divided by 10\n90\nYou are right<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-6-if-else-statements-in-bash\"><span class=\"ez-toc-section\" id=\"6-If-Else-Statements-in-Bash\"><\/span>6. If-Else Statements in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If-Else statements allow the shell interpreter to make the correct decision based on several conditions. If the condition in the if statement is not met, then a block of code between <code>else<\/code> and <code>fi<\/code> will be executed before continuing with the rest of the script. Note that if the if statement&#8217;s condition is met, then the code in the else block will <strong>not<\/strong> be executed. We&#8217;ll show you a bash script example on If-Else as well.<\/p>\n\n\n\n<p>For example, create a <code>test-else.sh<\/code> file with the following contents:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano test-else.sh<\/pre>\n\n\n\n<p>Add the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\na=10\nb=20\nif [ $a -gt $b ]\nthen\necho \"a is greater than b\"\nelse\necho \"a is less than b\"\nfi<\/pre>\n\n\n\n<p>Save the file and exit the text editor. Run the script with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash test-else.sh<\/pre>\n\n\n\n<p>This will print different messages based on whether the number is greater or less than the number it&#8217;s being compared to.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a is less than b<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-7-while-loops-in-bash\"><span class=\"ez-toc-section\" id=\"7-While-Loops-in-Bash\"><\/span>7. While Loops in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>A Loop allows you to run a series of commands a number of times until a particular condition is met. <code>While<\/code> loops execute a block of code over and over as long as the condition is met. As soon as the condition is no longer met, the loop exits.<\/p>\n\n\n\n<p>Loops are very useful for automating repetitive tasks. Make sure that the condition is eventually met, or the loop will continue indefinitely for as long as the computer\/server is on.<\/p>\n\n\n\n<p>The basic syntax of a <code>while<\/code> loop is shown below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">while [CONDITION]\ndo\n  [COMMANDS]\ndone<\/pre>\n\n\n\n<p>Let&#8217;s create a <code>test-while.sh<\/code> script file that will print the current value of the variable n and incremented by one.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano test-while.sh<\/pre>\n\n\n\n<p>Add the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\nn=0\nwhile [ $n -le 5 ]\ndo\n  echo Number: $n\n  ((n++))\ndone<\/pre>\n\n\n\n<p>Save and close the file then run the script with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash test-while.sh<\/pre>\n\n\n\n<p>The loop iterates as long as <code>n<\/code> is less than or equal to 5 and prints the following output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Number: 0\nNumber: 1\nNumber: 2\nNumber: 3\nNumber: 4\nNumber: 5<\/pre>\n\n\n\n<p>As soon as the condition is no longer met, the loop exits, and the program finishes executing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-8-for-loop-in-bash\"><span class=\"ez-toc-section\" id=\"8-For-Loop-in-Bash\"><\/span>8. For Loop in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For loops in bash are also useful for automating repetitive tasks.<\/p>\n\n\n\n<p>The basic syntax of a For Loop is shown below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for item in [LIST]\ndo\n  [COMMANDS]\ndone<\/pre>\n\n\n\n<p>For example, let&#8217;s create a <code>test-for.sh<\/code> script and use the for expression to specify a range of numbers or characters that we want to loop through.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano test-for.sh<\/pre>\n\n\n\n<p>Add the following contents:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\nfor n in {1..10}\ndo\n  echo \"Number: $n\"\ndone<\/pre>\n\n\n\n<p>Save and close the file, then execute the script with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash test-for.sh<\/pre>\n\n\n\n<p>This will print the number from 1 to 10, as shown below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Number: 1\nNumber: 2\nNumber: 3\nNumber: 4\nNumber: 5\nNumber: 6\nNumber: 7\nNumber: 8\nNumber: 9\nNumber: 10<\/pre>\n\n\n\n<p>The loop increments the variable until the condition is no longer met.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-9-read-from-a-file-in-bash\"><span class=\"ez-toc-section\" id=\"9-Read-from-a-File-in-Bash\"><\/span>9. Read from a File in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can read any file line-by-line using a loop in a bash script.<\/p>\n\n\n\n<p>First, create a file named file.txt with the following contents:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano file.txt<\/pre>\n\n\n\n<p>Add the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Linux\nUbuntu\nCentOS\nFedora\nDebian<\/pre>\n\n\n\n<p>We&#8217;re going to use this file as our example file. Save and close the file, then create a <code>test-file.sh<\/code> script:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano test-file.sh<\/pre>\n\n\n\n<p>Add the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\nfile='file.txt'\nwhile read line; do\necho $line\ndone &lt; $file<\/pre>\n\n\n\n<p>Save the file, then run the script that we just wrote using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash test-file.sh<\/pre>\n\n\n\n<p>You should see the following output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Linux\nUbuntu\nCentOS\nFedora\nDebian<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-10-check-if-a-file-or-directory-exists\"><span class=\"ez-toc-section\" id=\"10-Check-If-a-File-or-Directory-Exists\"><\/span>10. Check If a File or Directory Exists<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also check the existence of a file or directory using the -f and -d options in bash scripts.<\/p>\n\n\n\n<p>For example, create a <code>test-check.sh<\/code> file and check whether the specified file exists or not.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano test-check.sh<\/pre>\n\n\n\n<p>Add the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\nfilename=$1\nif [ -f \"$filename\" ]; then\necho \"File exists\"\nelse\necho \"File does not exist\"\nfi<\/pre>\n\n\n\n<p>In this script, we also show you how to pass arguments to a script when calling it from the command line. You do so by setting a variable to $1 for the first argument. <\/p>\n\n\n\n<p>Save the file, then run the script to check whether the <code>\/etc\/fstab<\/code> file exists:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash test-check.sh \/etc\/fstab<\/pre>\n\n\n\n<p>You should see the following output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">File exists<\/pre>\n\n\n\n<p>Next, create another script named <code>test-checkdir.sh<\/code> and check whether the specified directory exists or not.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano test-checkdir.sh<\/pre>\n\n\n\n<p>Add the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\ndirname=$1\nif [ -d \"$dirname\" ]; then\necho \"Directory exists\"\nelse\necho \"Directory does not exist\"\nfi<\/pre>\n\n\n\n<p>Save and close the file, then check whether the <code>\/opt<\/code> directory exists with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash test-checkdir.sh \/opt<\/pre>\n\n\n\n<p>You should get the following output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Directory exists<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>These are just a few examples of some basic bash script concepts and syntax. You can combine these blocks and statements to create a more complex and useful script.<\/p>\n\n\n\n<p>In the above guide, we showed you what bash scripts are, how they can be useful, and some bash script examples to help you get started with scripting.<\/p>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img decoding=\"async\" width=\"115\" height=\"115\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2020\/09\/managed-bash-script-automation-by-expert-admins-for-linux-vps.jpg\" alt=\"\" class=\"wp-image-34171\"\/><\/figure><\/div>\n\n\n\n<p>You can use bash scripts to automate tasks, but having someone else do it for you saves you even more time and effort than writing a script. If you use one of our <a href=\"https:\/\/www.rosehosting.com\/fully-managed.html\">fully managed Linux<\/a> web hosting solutions, you can simply ask our technical support to create a bash script to automate a task for you. Our experts can also help you just accomplish the task that you need instead of writing a script. They are available 24\/7 and will help you with any aspect of managing your server.<\/p>\n\n\n\n<p>If this post helped you learn about bash scripting, we would appreciate you sharing this post using our social media shortcuts. If you have any questions or comments, feel free to share them in the comments section below. Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will explain the most common bash operations while also showing you a few bash script examples. &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Bash Script Examples\" class=\"read-more button\" href=\"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#more-33968\" aria-label=\"Read more about Bash Script Examples\">Read More<\/a><\/p>\n","protected":false},"author":4,"featured_media":34169,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[1849,27],"class_list":["post-33968","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips-and-tricks","tag-bash-script-examples","tag-linux","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Bash Script Examples | RoseHosting<\/title>\n<meta name=\"description\" content=\"If you&#039;re new to bash scripting, our tutorial covers the essential functions and syntax needed to get started, including bash script examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bash Script Examples\" \/>\n<meta property=\"og:description\" content=\"Bash Script Examples | RoseHosting\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"RoseHosting\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/RoseHosting\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/rosehosting.helpdesk\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-07T16:32:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-06-03T08:32:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2020\/08\/bash-script-examples.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"742\" \/>\n\t<meta property=\"og:image:height\" content=\"372\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jeff Wilson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rosehosting\" \/>\n<meta name=\"twitter:site\" content=\"@rosehosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeff Wilson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/bash-script-examples\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/bash-script-examples\\\/\"},\"author\":{\"name\":\"Jeff Wilson\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/person\\\/7ce77a842fa6a9a7f8efa186f2353713\"},\"headline\":\"Bash Script Examples\",\"datePublished\":\"2020-09-07T16:32:53+00:00\",\"dateModified\":\"2022-06-03T08:32:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/bash-script-examples\\\/\"},\"wordCount\":1627,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/bash-script-examples\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/bash-script-examples.jpg\",\"keywords\":[\"bash script examples\",\"Linux\"],\"articleSection\":[\"Tips and Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/bash-script-examples\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/bash-script-examples\\\/\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/bash-script-examples\\\/\",\"name\":\"Bash Script Examples | RoseHosting\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/bash-script-examples\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/bash-script-examples\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/bash-script-examples.jpg\",\"datePublished\":\"2020-09-07T16:32:53+00:00\",\"dateModified\":\"2022-06-03T08:32:42+00:00\",\"description\":\"If you're new to bash scripting, our tutorial covers the essential functions and syntax needed to get started, including bash script examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/bash-script-examples\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/bash-script-examples\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/bash-script-examples\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/bash-script-examples.jpg\",\"contentUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/bash-script-examples.jpg\",\"width\":742,\"height\":372},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/bash-script-examples\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bash Script Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\",\"name\":\"RoseHosting.com\",\"description\":\"Premium Linux Tutorials Since 2001\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\",\"name\":\"RoseHosting\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/android-chrome-192x192-1.png\",\"contentUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/android-chrome-192x192-1.png\",\"width\":192,\"height\":192,\"caption\":\"RoseHosting\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/RoseHosting\",\"https:\\\/\\\/x.com\\\/rosehosting\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/rosehosting\\\/\"],\"description\":\"RoseHosting is a leading Linux hosting provider, serving thousands of clients world-wide since 2001.\",\"email\":\"info@rosehosting.com\",\"telephone\":\"(314) 275-0414\",\"legalName\":\"Rose Web Services LLC\",\"foundingDate\":\"2001-04-02\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"11\",\"maxValue\":\"50\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/person\\\/7ce77a842fa6a9a7f8efa186f2353713\",\"name\":\"Jeff Wilson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"caption\":\"Jeff Wilson\"},\"description\":\"An experienced Linux veteran with many years of experience. Helping other Linux admins with frequent Linux and business-related blog posts on the RoseHosting blog. Techie by choice. Loving nature and travel. Happily married and father of two lovely children.\",\"sameAs\":[\"https:\\\/\\\/www.rosehosting.com\",\"https:\\\/\\\/www.facebook.com\\\/rosehosting.helpdesk\"],\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/author\\\/jwilson\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Bash Script Examples | RoseHosting","description":"If you're new to bash scripting, our tutorial covers the essential functions and syntax needed to get started, including bash script examples.","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:\/\/www.rosehosting.com\/blog\/bash-script-examples\/","og_locale":"en_US","og_type":"article","og_title":"Bash Script Examples","og_description":"Bash Script Examples | RoseHosting","og_url":"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/","og_site_name":"RoseHosting","article_publisher":"https:\/\/www.facebook.com\/RoseHosting","article_author":"https:\/\/www.facebook.com\/rosehosting.helpdesk","article_published_time":"2020-09-07T16:32:53+00:00","article_modified_time":"2022-06-03T08:32:42+00:00","og_image":[{"width":742,"height":372,"url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2020\/08\/bash-script-examples.jpg","type":"image\/jpeg"}],"author":"Jeff Wilson","twitter_card":"summary_large_image","twitter_creator":"@rosehosting","twitter_site":"@rosehosting","twitter_misc":{"Written by":"Jeff Wilson","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#article","isPartOf":{"@id":"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/"},"author":{"name":"Jeff Wilson","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/person\/7ce77a842fa6a9a7f8efa186f2353713"},"headline":"Bash Script Examples","datePublished":"2020-09-07T16:32:53+00:00","dateModified":"2022-06-03T08:32:42+00:00","mainEntityOfPage":{"@id":"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/"},"wordCount":1627,"commentCount":1,"publisher":{"@id":"https:\/\/www.rosehosting.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2020\/08\/bash-script-examples.jpg","keywords":["bash script examples","Linux"],"articleSection":["Tips and Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/","url":"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/","name":"Bash Script Examples | RoseHosting","isPartOf":{"@id":"https:\/\/www.rosehosting.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#primaryimage"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2020\/08\/bash-script-examples.jpg","datePublished":"2020-09-07T16:32:53+00:00","dateModified":"2022-06-03T08:32:42+00:00","description":"If you're new to bash scripting, our tutorial covers the essential functions and syntax needed to get started, including bash script examples.","breadcrumb":{"@id":"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#primaryimage","url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2020\/08\/bash-script-examples.jpg","contentUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2020\/08\/bash-script-examples.jpg","width":742,"height":372},{"@type":"BreadcrumbList","@id":"https:\/\/www.rosehosting.com\/blog\/bash-script-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.rosehosting.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Bash Script Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.rosehosting.com\/blog\/#website","url":"https:\/\/www.rosehosting.com\/blog\/","name":"RoseHosting.com","description":"Premium Linux Tutorials Since 2001","publisher":{"@id":"https:\/\/www.rosehosting.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.rosehosting.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.rosehosting.com\/blog\/#organization","name":"RoseHosting","url":"https:\/\/www.rosehosting.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/03\/android-chrome-192x192-1.png","contentUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/03\/android-chrome-192x192-1.png","width":192,"height":192,"caption":"RoseHosting"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/RoseHosting","https:\/\/x.com\/rosehosting","https:\/\/www.linkedin.com\/in\/rosehosting\/"],"description":"RoseHosting is a leading Linux hosting provider, serving thousands of clients world-wide since 2001.","email":"info@rosehosting.com","telephone":"(314) 275-0414","legalName":"Rose Web Services LLC","foundingDate":"2001-04-02","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"11","maxValue":"50"}},{"@type":"Person","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/person\/7ce77a842fa6a9a7f8efa186f2353713","name":"Jeff Wilson","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","caption":"Jeff Wilson"},"description":"An experienced Linux veteran with many years of experience. Helping other Linux admins with frequent Linux and business-related blog posts on the RoseHosting blog. Techie by choice. Loving nature and travel. Happily married and father of two lovely children.","sameAs":["https:\/\/www.rosehosting.com","https:\/\/www.facebook.com\/rosehosting.helpdesk"],"url":"https:\/\/www.rosehosting.com\/blog\/author\/jwilson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/33968","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/comments?post=33968"}],"version-history":[{"count":12,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/33968\/revisions"}],"predecessor-version":[{"id":38376,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/33968\/revisions\/38376"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/media\/34169"}],"wp:attachment":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/media?parent=33968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/categories?post=33968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/tags?post=33968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}