{"id":3344,"date":"2023-07-06T02:57:43","date_gmt":"2023-07-06T02:57:43","guid":{"rendered":"https:\/\/www.copahost.com\/blog\/?p=3344"},"modified":"2023-07-06T02:58:55","modified_gmt":"2023-07-06T02:58:55","slug":"compare-strings-bash","status":"publish","type":"post","link":"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/","title":{"rendered":"Compare Strings In Bash"},"content":{"rendered":"\n<p>When working with strings in Bash, it is often necessary to compare them in order to execute commands based on their values. In Bash, as in other programming languages, string comparisons are done with the if conditionals and comparison operators. In this article, we&#8217;ll cover how these operators are used to compare strings, giving examples of each.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_69_1 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/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:\/\/www.copahost.com\/blog\/compare-strings-bash\/#Comparison_Operators\" title=\"Comparison Operators\">Comparison Operators<\/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.copahost.com\/blog\/compare-strings-bash\/#Examples\" title=\"Examples\">Examples<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#Check_If_Two_Strings_Are_Equal\" title=\"Check If Two Strings Are Equal\">Check If Two Strings Are Equal<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#Check_If_Two_Strings_Are_Not_Equal\" title=\"Check If Two Strings Are Not Equal\">Check If Two Strings Are Not Equal<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#Alphabetical_Comparison\" title=\"Alphabetical Comparison\">Alphabetical Comparison<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#Pattern_Matching\" title=\"Pattern Matching\">Pattern Matching<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#Check_If_A_String_Contains_A_Specific_Substring\" title=\"Check If A String Contains A Specific Substring\">Check If A String Contains A Specific Substring<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#Check_If_A_String_is_Empty_Or_Not\" title=\"Check If A String is Empty Or Not\">Check If A String is Empty Or Not<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#Conclusion\" title=\"Conclusion\">Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Comparison_Operators\"><\/span>Comparison Operators<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The comparison operators are used to compare the values of strings. They return a boolean value of true or false depending on the comparison result. Here are the most used string comparison operators in Bash.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Equal (<code>==<\/code>) or (<code>=<\/code>):<\/strong> This operator tests if two strings are equal.<\/li>\n\n\n\n<li><strong>Not Equal (<code>!=<\/code>):<\/strong> It checks if two strings are not equal.<\/li>\n\n\n\n<li><strong>Greater Than (<code>&gt;<\/code>):<\/strong> This operator compares two strings alphabetically and checks if the first string is greater than the second.<\/li>\n\n\n\n<li><strong>Less Than (<code>&lt;<\/code>):<\/strong> It compares two strings alphabetically and checks if the first string is less than the second.<\/li>\n\n\n\n<li><strong>Greater Than or Equal To (<code>&gt;=<\/code>):<\/strong> This operator checks if the first string is greater than or equal to the second.<\/li>\n\n\n\n<li><strong>Less Than or Equal To (<code>&lt;=<\/code>):<\/strong> It checks if the first string is less than or equal to the second.<\/li>\n\n\n\n<li><strong>Pattern matching (<code>=~<\/code><\/strong>): This operator checks if a string matches a specific pattern using regular expressions.<\/li>\n\n\n\n<li><strong>Substring containment(<code>*<\/code>)<\/strong>: It checks if a string contains a specific substring,<\/li>\n\n\n\n<li><strong>Empty string<\/strong> <strong>(<code>-z<\/code>):<\/strong> This operator checks if a string is empty.<\/li>\n\n\n\n<li><strong>Non-empty string<\/strong> <strong>(<code>-n<\/code>)<\/strong>: This operator checks if a string is non-empty.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Examples\"><\/span>Examples<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Now, you can create a bash file with the <code>.sh<\/code> extension and open it with a command line editor to compare strings. Here is an example of opening a file with the nano editor available on Linux and MacOs operating systems.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch comparison.sh \/\/ Create a bash file\nnano comparison.sh \/\/ Open the file\nbash comparison.sh \/\/ Run the commands in the file<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Check_If_Two_Strings_Are_Equal\"><\/span>Check If Two Strings Are Equal<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>To check if two strings are equal, you can use the <code>=<\/code> operator with the single brackets <code>[]<\/code> or  the <code>==<\/code> operator with the double square brackets <code>[[ ]]<\/code>. Here&#8217;s an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nstring1=\"Hello\"\nstring2=\"Hello\"\n\nif &#091; \"$string1\" = \"$string2\" ]; then\n    echo \"The strings are equal.\"\nfi\n\nif &#091;&#091; \"$string1\" == \"$string2\" ]]; then\n    echo \"The strings are also equal.\"\nfi<\/code><\/pre>\n\n\n\n<p>When it is executed, the result would look like:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal-1024x557.png\" alt=\"Check if two strings are equal in bash\" class=\"wp-image-3345\" width=\"842\" height=\"457\" srcset=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal-1024x557.png 1024w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal-300x163.png 300w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal-768x418.png 768w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal-145x80.png 145w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal.png 1364w\" sizes=\"(max-width: 842px) 100vw, 842px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Check_If_Two_Strings_Are_Not_Equal\"><\/span>Check If Two Strings Are Not Equal<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>To check if two strings are not equal,  you can use the <code>!=<\/code> operator with the single brackets <code>[]<\/code> or the double square brackets <code>[[ ]]<\/code>. Here&#8217;s an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nstring1=\"Hello\"\nstring2=\"World\"\n\nif &#091; \"$string1\" != \"$string2\" ]; then\n    echo \"The strings are not equal.\"\nfi\n\nif &#091;&#091; \"$string1\" != \"$string2\" ]]; then\n    echo \"The strings are also not equal.\"\nfi<\/code><\/pre>\n\n\n\n<p>In this case, both if conditions will be satisfied, as string1 and string2 are not equal. The output will be:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"557\" src=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-not-equal-1024x557.png\" alt=\"Check if two strings are not equal in bash\" class=\"wp-image-3346\" srcset=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-not-equal-1024x557.png 1024w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-not-equal-300x163.png 300w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-not-equal-768x418.png 768w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-not-equal-145x80.png 145w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-not-equal.png 1364w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Alphabetical_Comparison\"><\/span>Alphabetical Comparison<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>To compare strings based on their alphabetical order, you can use the <code>&lt;<\/code>, <code>&gt;<\/code>, <code>&lt;=<\/code>, and <code>&gt;=<\/code> operators. Here&#8217;s an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nstring1=\"Apple\"\nstring2=\"Banana\"\n\nif &#091;&#091; \"$string1\" &lt; \"$string2\" ]]; then\n    echo \"string1 comes before string2.\"\nfi\n\nif &#091;&#091; \"$string1\" &gt; \"$string2\" ]]; then\n    echo \"string1 comes after string2.\"\nfi<\/code><\/pre>\n\n\n\n<p>In this example, the first <code>if<\/code> condition will be satisfied since &#8220;Apple&#8221; comes before &#8220;Banana&#8221; in alphabetical order. Here is the result:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/Alphabetical-Comparison-in-bash-1024x557.png\" alt=\"Alphabetical Comparison of Two Strings in Bash\" class=\"wp-image-3347\" width=\"840\" height=\"456\" srcset=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/Alphabetical-Comparison-in-bash-1024x557.png 1024w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/Alphabetical-Comparison-in-bash-300x163.png 300w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/Alphabetical-Comparison-in-bash-768x418.png 768w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/Alphabetical-Comparison-in-bash-145x80.png 145w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/Alphabetical-Comparison-in-bash.png 1364w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Pattern_Matching\"><\/span>Pattern Matching<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The pattern matching operator checks if a string matches a specific pattern using regular expressions. Here is an example of how to check if a string contains only numbers.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nstring1=\"234\"\n\nif &#091;&#091; $string1 =~ ^&#091;0-9]+$ ]]; then\n    echo \"String consists of digits only\"\nelse\n    echo \"String contains non-digit characters\"\nfi<\/code><\/pre>\n\n\n\n<p>As the string only contains of numbers, the result will be like:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/pattern-matching-operator-in-bash-1024x557.png\" alt=\"Pattern matching operator in bash\" class=\"wp-image-3369\" width=\"842\" height=\"457\" srcset=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/pattern-matching-operator-in-bash-1024x557.png 1024w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/pattern-matching-operator-in-bash-300x163.png 300w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/pattern-matching-operator-in-bash-768x418.png 768w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/pattern-matching-operator-in-bash-145x80.png 145w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/pattern-matching-operator-in-bash.png 1364w\" sizes=\"(max-width: 842px) 100vw, 842px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Check_If_A_String_Contains_A_Specific_Substring\"><\/span>Check If A String Contains A Specific Substring<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>To check if a string contains a specific substring at the beginning or the end, you can use the <strong><code>*<\/code><\/strong> (asterisk) symbol.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nstring=\"HelloWorld\"\n\nif &#091;&#091; \"$string\" == *ello* ]]; then\n     echo \"String contains 'ello' substring\"\nfi\n\nif &#091;&#091; \"$string\" == Hello* ]]; then\n     echo \"String contains 'Hello' at the beginning\"\nfi\n\nif &#091;&#091; \"$string\" == *World ]]; then\n     echo \"String contains 'World' at the end\"\nfi<\/code><\/pre>\n\n\n\n<p>The all conditions will be satisfied and the script will generate the following output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"557\" src=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/substring-in-bash-1024x557.png\" alt=\"Check If A String Contains A Specific Substring\" class=\"wp-image-3370\" srcset=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/substring-in-bash-1024x557.png 1024w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/substring-in-bash-300x163.png 300w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/substring-in-bash-768x418.png 768w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/substring-in-bash-145x80.png 145w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/substring-in-bash.png 1364w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Check_If_A_String_is_Empty_Or_Not\"><\/span>Check If A String is Empty Or Not<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>To check if a string is empty or not, you can use the <code>-z<\/code> and <code>n<\/code> operators. Here is an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nstring=\"\"\n\nif &#091;&#091; -z \"$string\" ]]; then\n     echo \"String is empty\"\nfi\n\nif &#091;&#091; -n \"$string\" ]]; then\n     echo \"String is not empty\"\nfi<\/code><\/pre>\n\n\n\n<p>Since the string is empty, the output will be:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"557\" src=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-empty-string-1024x557.png\" alt=\"Check If A String is Empty Or Not in Bash\" class=\"wp-image-3373\" srcset=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-empty-string-1024x557.png 1024w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-empty-string-300x163.png 300w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-empty-string-768x418.png 768w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-empty-string-145x80.png 145w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-empty-string.png 1364w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Comparing strings is a common operation when writing Bash scripts. In Bash, there are several operators that we can use for this purpose, as a <a href=\"https:\/\/www.copahost.com\/blog\/bash-commenting-3-ways-to-use-comments\/\">comment<\/a>. These operators offer a wide variety of options and they can be combined with conditional statements (<code>if<\/code>, <code>elif<\/code>, <code>else<\/code>) to perform different actions based on the comparison results.<\/p>\n\n\n\n<p>Thank you for reading<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When working with strings in Bash, it is often necessary to compare them in order to execute commands based on their values. In Bash, as in other programming languages, string comparisons are done with the if conditionals and comparison operators. In this article, we&#8217;ll cover how these operators are used to compare strings, giving examples [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"class_list":["post-3344","post","type-post","status-publish","format-standard","hentry","category-linux-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Compare Strings In Bash - Copahost<\/title>\n<meta name=\"description\" content=\"Compare strings in bash using various operators and if conditionals | How to Check If Two Strings Are Equal in Bash\" \/>\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.copahost.com\/blog\/compare-strings-bash\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Compare Strings In Bash - Copahost\" \/>\n<meta property=\"og:description\" content=\"Compare strings in bash using various operators and if conditionals | How to Check If Two Strings Are Equal in Bash\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/\" \/>\n<meta property=\"og:site_name\" content=\"Copahost\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-06T02:57:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-06T02:58:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal-1024x557.png\" \/>\n<meta name=\"author\" content=\"Bruno C\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bruno C\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/\"},\"author\":{\"name\":\"Bruno C\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#\/schema\/person\/e6431232917246b162e977b6ae982cf2\"},\"headline\":\"Compare Strings In Bash\",\"datePublished\":\"2023-07-06T02:57:43+00:00\",\"dateModified\":\"2023-07-06T02:58:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/\"},\"wordCount\":598,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal-1024x557.png\",\"articleSection\":[\"Linux tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/\",\"url\":\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/\",\"name\":\"Compare Strings In Bash - Copahost\",\"isPartOf\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal-1024x557.png\",\"datePublished\":\"2023-07-06T02:57:43+00:00\",\"dateModified\":\"2023-07-06T02:58:55+00:00\",\"description\":\"Compare strings in bash using various operators and if conditionals | How to Check If Two Strings Are Equal in Bash\",\"breadcrumb\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#primaryimage\",\"url\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal.png\",\"contentUrl\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal.png\",\"width\":1364,\"height\":742},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.copahost.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Compare Strings In Bash\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#website\",\"url\":\"https:\/\/www.copahost.com\/blog\/\",\"name\":\"Copahost\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.copahost.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#organization\",\"name\":\"Copahost\",\"url\":\"https:\/\/www.copahost.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2016\/03\/copahostlogo.png\",\"contentUrl\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2016\/03\/copahostlogo.png\",\"width\":223,\"height\":40,\"caption\":\"Copahost\"},\"image\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#\/schema\/person\/e6431232917246b162e977b6ae982cf2\",\"name\":\"Bruno C\",\"description\":\"I'm a developer.\",\"url\":\"https:\/\/www.copahost.com\/blog\/author\/buildev\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Compare Strings In Bash - Copahost","description":"Compare strings in bash using various operators and if conditionals | How to Check If Two Strings Are Equal in Bash","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.copahost.com\/blog\/compare-strings-bash\/","og_locale":"en_US","og_type":"article","og_title":"Compare Strings In Bash - Copahost","og_description":"Compare strings in bash using various operators and if conditionals | How to Check If Two Strings Are Equal in Bash","og_url":"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/","og_site_name":"Copahost","article_published_time":"2023-07-06T02:57:43+00:00","article_modified_time":"2023-07-06T02:58:55+00:00","og_image":[{"url":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal-1024x557.png"}],"author":"Bruno C","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Bruno C","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#article","isPartOf":{"@id":"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/"},"author":{"name":"Bruno C","@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/person\/e6431232917246b162e977b6ae982cf2"},"headline":"Compare Strings In Bash","datePublished":"2023-07-06T02:57:43+00:00","dateModified":"2023-07-06T02:58:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/"},"wordCount":598,"commentCount":0,"publisher":{"@id":"https:\/\/www.copahost.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#primaryimage"},"thumbnailUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal-1024x557.png","articleSection":["Linux tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/","url":"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/","name":"Compare Strings In Bash - Copahost","isPartOf":{"@id":"https:\/\/www.copahost.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#primaryimage"},"image":{"@id":"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#primaryimage"},"thumbnailUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal-1024x557.png","datePublished":"2023-07-06T02:57:43+00:00","dateModified":"2023-07-06T02:58:55+00:00","description":"Compare strings in bash using various operators and if conditionals | How to Check If Two Strings Are Equal in Bash","breadcrumb":{"@id":"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.copahost.com\/blog\/compare-strings-bash\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#primaryimage","url":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal.png","contentUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/07\/check-if-two-strings-are-equal.png","width":1364,"height":742},{"@type":"BreadcrumbList","@id":"https:\/\/www.copahost.com\/blog\/compare-strings-bash\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.copahost.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Compare Strings In Bash"}]},{"@type":"WebSite","@id":"https:\/\/www.copahost.com\/blog\/#website","url":"https:\/\/www.copahost.com\/blog\/","name":"Copahost","description":"","publisher":{"@id":"https:\/\/www.copahost.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.copahost.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.copahost.com\/blog\/#organization","name":"Copahost","url":"https:\/\/www.copahost.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2016\/03\/copahostlogo.png","contentUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2016\/03\/copahostlogo.png","width":223,"height":40,"caption":"Copahost"},"image":{"@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/person\/e6431232917246b162e977b6ae982cf2","name":"Bruno C","description":"I'm a developer.","url":"https:\/\/www.copahost.com\/blog\/author\/buildev\/"}]}},"_links":{"self":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts\/3344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/comments?post=3344"}],"version-history":[{"count":5,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts\/3344\/revisions"}],"predecessor-version":[{"id":3419,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts\/3344\/revisions\/3419"}],"wp:attachment":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/media?parent=3344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/categories?post=3344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/tags?post=3344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}