{"id":35251,"date":"2024-01-28T10:02:32","date_gmt":"2024-01-28T10:02:32","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=35251"},"modified":"2024-04-01T06:46:05","modified_gmt":"2024-04-01T06:46:05","slug":"bash-check-string","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/","title":{"rendered":"Check String in Bash"},"content":{"rendered":"<p style=\"text-align: justify;\">In Bash, checking strings for certain conditions is a fundamental aspect of writing a robust script. It\u2019s a common task of string manipulation which is a powerful tool for scripting and automations. In this article, I\u2019ll explore 5 cases to check strings on various constraints like checking empty strings, equality check, finding a substring in a string, and more.<\/p>\n<p>Now, let&#8217;s dive into these <strong>5 cases to check string in Bash<\/strong>:<\/p>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/Check-string-in-Bash.zip\" class=\"su-button su-button-style-default\" style=\"color:#000000;background-color:#E8F9FF;border-color:#bac8cc;border-radius:56px\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color:#000000;padding:8px 26px;font-size:20px;line-height:30px;border-color:#effbff;border-radius:56px;text-shadow:0px 0px 0px #000000\"><i class=\"sui sui-download\" style=\"font-size:20px;color:#1AA1D6\"><\/i> Practice Files to Check String in Bash.<\/span><\/a><\/div>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 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\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#1_Check_Empty_string\" >1. Check Empty string<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#2_Check_the_Equality_of_Strings\" >2. Check the Equality of Strings<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#3_Check_If_the_String_Contains_a_Substring\" >3. Check If the String Contains a Substring<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#4_Check_If_the_String_Starts_with_a_Specific_Value\" >4. Check If the String Starts with a Specific Value<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#5_Check_the_Lexicographical_Order_of_String\" >5. Check the Lexicographical Order of String<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#People_Also_Ask\" >People Also Ask<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#How_to_compare_string_lengths_in_Bash\" >How to compare string lengths in Bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#How_to_use_%E2%80%9Cregex%E2%80%9D_in_Bash_for_searching_within_strings\" >How to use \u201cregex\u201d in Bash for searching within strings?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#How_to_check_if_the_string_contains_only_numeric_characters_or_not\" >How to check if the string contains only numeric characters or not?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#How_to_check_if_a_string_is_empty_using_the_%E2%80%9C-n%E2%80%9D_option\" >How to check if a string is empty using the \u201c-n\u201d option?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#How_to_check_if_a_variable_string_begins_with_another_string\" >How to check if a variable string begins with another string?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"1_Check_Empty_string\"><\/span>1. Check Empty string<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In bash, it\u2019s common to check for an empty string which refers to a string with zero length. Certainly, Bash offers various operators to check the status of strings such as the <code class=\"\" data-line=\"\">-z<\/code> or <code class=\"\" data-line=\"\">-n<\/code> option and the equality <code class=\"\" data-line=\"\">==<\/code>, or inequality <code class=\"\" data-line=\"\">!=<\/code> operators.<\/p>\n<p style=\"text-align: justify;\">For example, to check if a string is empty or not, you can use the <code class=\"\" data-line=\"\">-z<\/code> option within the <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/conditional-statements\/if-else\/\" target=\"_blank\" rel=\"noopener\"><strong>if-else<\/strong><\/a> condition. Follow the script below to check if a string is empty practically:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Define an empty string\nstring=&quot;&quot;\n\n# Check if the variable is empty using -z\nif [ -z &quot;$string&quot; ]; then\necho &quot;The string is empty&quot;\nelse\necho &quot;The string is not empty&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\"><div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">Here, the <code class=\"\" data-line=\"\">-z<\/code> option in the condition <code class=\"\" data-line=\"\">[ -z &quot;$string&quot; ]<\/code> checks if the length of the variable <strong>$string <\/strong>is zero. Based on the returned value, the <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/output\/echo-command\/\" target=\"_blank\" rel=\"noopener\"><strong>echo<\/strong><\/a> command displays whether the string is empty or not.<\/div><\/div>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-35253 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/1-check_empty_string.png\" alt=\"Check if a string is empty using -z option in if-else statement.\" width=\"548\" height=\"105\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/1-check_empty_string.png 548w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/1-check_empty_string-300x57.png 300w\" sizes=\"(max-width: 548px) 100vw, 548px\" \/>The output shows that \u201cThe string is empty\u201d as the length of the string variable is zero.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"2_Check_the_Equality_of_Strings\"><\/span>2. Check the Equality of Strings<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">String equality refers to comparing two strings and checking if they are equal or not. It can be checked by using the single equal <code class=\"\" data-line=\"\">=<\/code><strong>,<\/strong> double equal <code class=\"\" data-line=\"\">==<\/code> operator<strong>, <\/strong>or <strong>test <\/strong>command within the <strong>if-else<\/strong>\u00a0statement.<\/p>\n<p>For example, to check if two strings are equal or not, follow the script below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#Define two string variables\nstring1=&quot;Linuxsimply&quot;\nstring2=&quot;Linuxsimply&quot;\n\n#Print the declared strings\necho &quot;Frist string: $string1&quot;\necho &quot;Second String: $string2&quot;\n\n#check two strings equality\nif [[ &quot;$string1&quot; == &quot;$string2&quot; ]]; then\necho &quot;strings are equal&quot;\nelse\necho &quot;strings are different&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\"><div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">The condition<code class=\"\" data-line=\"\">\u00a0&quot;$string1&quot; == &quot;$string2&quot;<\/code> within the <strong>if-else <\/strong>statement compares <strong>string1 <\/strong>and <strong>string2 <\/strong>and checks their equality with the double equal <code class=\"\" data-line=\"\">==<\/code> operator.<\/div><\/div>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"aligncenter wp-image-35254 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/2-Check-equality.png\" alt=\"Checking the equality of strings using double equal (==) operator.\" width=\"649\" height=\"137\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/2-Check-equality.png 649w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/2-Check-equality-300x63.png 300w\" sizes=\"(max-width: 649px) 100vw, 649px\" \/>The output shows that the strings are equal to each other.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"3_Check_If_the_String_Contains_a_Substring\"><\/span>3. Check If the String Contains a Substring<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Checking if a string contains another string or substring is called partial comparison. You can use the wildcard character <code class=\"\" data-line=\"\">*<\/code>, the \u201cgrep\u201d command, or even use the \u201ccase\u201d statement to check if the string contains a specific substring.<\/p>\n<p style=\"text-align: justify;\">Check the following script to check if a string contains the substring using wildcard character (*) and double equal (\u2018==\u2019) operator:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#Define a string and another variable with the substring to check.\nstring=&quot;Check if the string contains a substring.&quot;\nsubstring=&quot;substring&quot;\n\n#Print the declared strings\necho &quot;Frist string: $string1&quot;\necho &quot;Second String: $string2&quot;\n\n#checking the substring into the string\nif [[ &quot;$string&quot; == *&quot;$substring&quot;* ]]; then\necho &quot;Substring found: $substring&quot;\nelse\necho &quot;Substring not found: $substring&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\"><div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">Here, <code class=\"\" data-line=\"\">[[ &quot;$string&quot; == *&quot;$substring&quot;* ]]<\/code>\u00a0statement checks if the main string contains a specified substring. The <code class=\"\" data-line=\"\">==<\/code> operator is used for string comparison and the wildcard <code class=\"\" data-line=\"\">*<\/code> is used to match the substring considering any characters before and after the substring.<\/div><\/div>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"aligncenter wp-image-35255 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/3-Check-a-string-contain-a-substring.png\" alt=\"Checking if a substring is found in a string.\" width=\"700\" height=\"136\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/3-Check-a-string-contain-a-substring.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/3-Check-a-string-contain-a-substring-300x58.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/>After searching for the substring in the <strong>string, <\/strong>the output shows \u201csubstring found\u201d.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"4_Check_If_the_String_Starts_with_a_Specific_Value\"><\/span>4. Check If the String Starts with a Specific Value<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">You can check whether a string starts with a specific value or not using the <strong>wildcard (*) <\/strong>character after the specific value. To check if a string starts with a specific value, you can check the following script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Define the first string\nstring=&quot;LinuxSimply&quot;\n\n#Check if the string starts with some value\nif [[ $string = L* ]]\nthen\necho &quot;Start with L&quot;\nelse\necho &quot;No match&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\"><div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">The conditional statement <code class=\"\" data-line=\"\">[[ $input = L* ]]<\/code> checks if the value of the <strong>string <\/strong>begins with <code class=\"\" data-line=\"\">L<\/code>. If the condition is true, the following block of code is executed.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-35256 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/4.-Check-string-starts-with-value.png\" alt=\"Checking if a string begins with any specific value.\" width=\"700\" height=\"128\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/4.-Check-string-starts-with-value.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/4.-Check-string-starts-with-value-300x55.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/>The output shows that \u201cThe string starts with L\u201d after checking whether the <strong>string <\/strong>starts with the specified value \u201cL\u201d.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"5_Check_the_Lexicographical_Order_of_String\"><\/span>5. Check the Lexicographical Order of String<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Lexicographical comparison refers to comparing a string based on alphabetical order or dictionary order. The lexicographical comparison usually relies on the ASCII or Unicode values of the characters. In the ASCII system, each character is assigned a numerical value. Lexicographical comparison is executed based on these numerical values. Characters with lower numerical values are positioned before characters with higher numerical values.<\/p>\n<p style=\"text-align: justify;\">Follow the below script to check the lexicographical order of strings:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Define the first string\nstringA=&quot;Orange&quot;\n\n# Define the second string\nstringB=&quot;Apple&quot;\n\n#Print the declared strings\necho &quot;Frist string: $stringA&quot;\necho &quot;Second String: $stringB&quot;\n\n# Check lexicographical order\nif [[ &quot;$stringA&quot; &lt; &quot;$stringB&quot; ]]; then\necho &quot;Lexicographical order: $stringA $stringB&quot;\nelse\necho &quot;Lexicographical order: $stringB $stringA&quot;\nfi<\/code><\/pre>\n<p style=\"text-align: justify;\"><div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\"> Here, the <code class=\"\" data-line=\"\">[[ &quot;$stringA&quot; &lt; &quot;$stringB&quot; ]]<\/code> condition of <strong>if <\/strong>block checks if <strong>stringA <\/strong>is less than <strong>stringB <\/strong>or not. The <strong>else <\/strong>block checks the opposite.<\/p>\n<\/div><\/div>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-35257 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/5.-Lexicographic-order.png\" alt=\"Sorting strings in lexicographical order.\" width=\"700\" height=\"130\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/5.-Lexicographic-order.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/5.-Lexicographic-order-300x56.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/>The output shows the sorted order of <strong>stringA <\/strong>and <strong>stringB <\/strong>according to the lexicographical order.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">To sum up, this article discusses 5 cases of checking strings in Bash, encompassing checks for empty strings, equality, lexicographical order, and more. Hope this article guides you and clears your vision on Bash check strings to smooth the ways of string manipulation.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"People_Also_Ask\"><\/span>People Also Ask<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"How_to_compare_string_lengths_in_Bash\"><\/span>How to compare string lengths in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To compare the length of strings for your convenience, use the equal <code class=\"\" data-line=\"\">-eq<\/code> operator. See the below script for a practical approach:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#define two strings\nstring1=&quot;LinuxSimply&quot;\nstring2=&quot;Linux&quot;\n\n#Compare the string lengths\nif [ ${#string1} -eq ${#string2} ]; then\necho &quot;Strings are of equal length.&quot;\nelse\necho &quot;Strings are of different lengths.&quot;\nfi\n\n## Output\nStrings are of different lengths.<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"How_to_use_%E2%80%9Cregex%E2%80%9D_in_Bash_for_searching_within_strings\"><\/span>How to use \u201cregex\u201d in Bash for searching within strings?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Regular expression (regex) is a sequence of characters that defines a search pattern. It provides a tool for pattern matching and searching within strings. Regular expressions are used in various programming languages, text editors, and command-line tools for tasks such as searching, matching, and manipulating text based on specific patterns.<\/p>\n<p>To use regex expression, you can use the <code class=\"\" data-line=\"\">[[<\/code> keyword along with the <code class=\"\" data-line=\"\">=~<\/code> operator to perform expression matching. Here\u2019s a basic example to check if a string contains any numbers:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#Declare the string\nstring=&quot;Hello, world!&quot;\n\n# Check if the string matches a basic pattern\nif [[ $string =~ [0-9]+ ]]; then\necho &quot;String contains a number.&quot;\nelse\necho &quot;No numbers found in the string.&quot;\nfi\n\n##Output\nNo numbers found in the string.<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"How_to_check_if_the_string_contains_only_numeric_characters_or_not\"><\/span>How to check if the string contains only numeric characters or not?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To check whether the string contains only numeric characters or not, you can use regex <code class=\"\" data-line=\"\">=~<\/code> within the <strong>if-else <\/strong>statement. To check if the string contains numeric characters only, follow the below script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#define the string\nstring=&quot;123&quot;\n\n#check if the string contains only numerical characters\nif [[ &quot;$string&quot; =~ ^[0-9]+$ ]]; then\necho &quot;String contains only numbers.&quot;\nelse\necho &quot;String contains non-numeric characters.&quot;\nfi\n\n##Output\nString contains only numbers.<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_check_if_a_string_is_empty_using_the_%E2%80%9C-n%E2%80%9D_option\"><\/span>How to check if a string is empty using the \u201c-n\u201d option?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To check if a string is empty, use the <code class=\"\" data-line=\"\">-n<\/code> option within the <strong>if-else <\/strong>statement that checks string length using <code class=\"\" data-line=\"\">[ -n \u201c$string\u201d ]<\/code> syntax. If the string length is not zero, it evaluates <strong>true<\/strong>, otherwise, it evaluates <strong>false <\/strong>and the \u201celse\u201d block will find the empty string.<strong>\u00a0<\/strong>To check if a string is empty or not, follow the below script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#Declare strings\nstring=&quot;&quot;\n\n#Check if the string is empty using &quot;-n&quot; option\nif [ -n &quot;$string&quot; ]; then\necho &quot;The string is not empty.&quot;\nelse\necho &quot;The string is empty.&quot;\nfi\n\n####Output\nThe string is empty.<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"How_to_check_if_a_variable_string_begins_with_another_string\"><\/span>How to check if a variable string begins with another string?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">You can use the regex operator (=~) to check whether a variable string starts with another string or not. Follow the below script for a better understanding:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n#Declare strings\nstring=&quot;Linux Simply&quot;\nprefix=&quot;Linux&quot;\n\n#check if the string starts with the other string\nif [[ &quot;$string&quot; =~ ^&quot;$prefix&quot; ]]; then\necho &quot;The string starts with the \u201cLinux\u201d.&quot;\nelse\necho &quot;The string does not start with the \u201cLinux\u201d.&quot;\nfi\n\n####Output\nThe string starts with the \u201cLinux\u201d.<\/code><\/pre>\n<p><span style=\"font-size: 18pt; color: #003366;\"><strong>Related Articles<\/strong><\/span><\/p>\n<ul>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/check-if-string-starts-with\/\" target=\"_blank\" rel=\"noopener\">Check If Bash String Starts with Some Value [4 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/if-string-equals\/\" target=\"_blank\" rel=\"noopener\">Check If A String Equals to Another String in Bash [5 Methods]<\/a><\/strong><\/li>\n<\/ul>\n<hr \/>\n<p><strong>&lt;&lt; Go Back to <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash String&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1074113,&quot;3&quot;:{&quot;1&quot;:0},&quot;9&quot;:1,&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;16&quot;:12,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/\" target=\"_blank\" rel=\"noopener\">Bash String<\/a><\/span> | <span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Scripting Tutorial&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:1074113,&quot;3&quot;:{&quot;1&quot;:0},&quot;9&quot;:1,&quot;10&quot;:1,&quot;11&quot;:4,&quot;12&quot;:0,&quot;16&quot;:12,&quot;17&quot;:1,&quot;23&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Tutorial<\/a><\/span><\/strong><\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-center kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;center&quot;,&quot;id&quot;:&quot;35251&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;Check String in Bash&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\">Rate this post<\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>In Bash, checking strings for certain conditions is a fundamental aspect of writing a robust script. It\u2019s a common task &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Check String in Bash\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#more-35251\" aria-label=\"Read more about Check String in Bash\">Read more<\/a><\/p>\n","protected":false},"author":314912,"featured_media":35258,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[189],"class_list":["post-35251","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-bash-string","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Check String in Bash - LinuxSimply<\/title>\n<meta name=\"description\" content=\"In Bash, checking strings&#039; various features like if they are empty, equal, or substring matching is crucial to manipulating strings.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Check String in Bash - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"In Bash, checking strings&#039; various features like if they are empty, equal, or substring matching is crucial to manipulating strings.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/profile.php?id=100077694755838&amp;mibextid=ZbWKwL\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-28T10:02:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-01T06:46:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/6.-Feature-image.png\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Auhona Islam\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Auhona Islam\" \/>\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:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/check-string\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/check-string\\\/\"},\"author\":{\"name\":\"Auhona Islam\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/25a3d16db4655804617c9e0c4a7989fb\"},\"headline\":\"Check String in Bash\",\"datePublished\":\"2024-01-28T10:02:32+00:00\",\"dateModified\":\"2024-04-01T06:46:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/check-string\\\/\"},\"wordCount\":1059,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/check-string\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/6.-Feature-image.png\",\"keywords\":[\"bash string\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/check-string\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/check-string\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/check-string\\\/\",\"name\":\"Check String in Bash - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/check-string\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/check-string\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/6.-Feature-image.png\",\"datePublished\":\"2024-01-28T10:02:32+00:00\",\"dateModified\":\"2024-04-01T06:46:05+00:00\",\"description\":\"In Bash, checking strings' various features like if they are empty, equal, or substring matching is crucial to manipulating strings.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/check-string\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/check-string\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/check-string\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/6.-Feature-image.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/6.-Feature-image.png\",\"width\":400,\"height\":400,\"caption\":\"Check string in Bash.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/check-string\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bash Scripting Tutorial\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Bash String\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Check String in Bash\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"name\":\"LinuxSimply\",\"description\":\"All About Linux\",\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/linuxsimply.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\",\"name\":\"LinuxSimply\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"width\":355,\"height\":48,\"caption\":\"LinuxSimply\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/25a3d16db4655804617c9e0c4a7989fb\",\"name\":\"Auhona Islam\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Auhona-Islam-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Auhona-Islam-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Auhona-Islam-II-96x96.png\",\"caption\":\"Auhona Islam\"},\"description\":\"Auhona Islam is a dedicated professional with a background in Electronics and Communication Engineering (ECE) from Khulna University of Engineering &amp; Technology. Graduating in 2023, Auhona is currently excelling in her role as a Linux content developer executive at SOFTEKO to provide a more straightforward route for Linux users. She aims to generate compelling materials for Linux users with her knowledge and skills. She holds her enthusiasm in the realm of Machine Learning (ML), Deep Learning (DL), and Artificial Intelligence (AI). Apart from these, she has a passion for playing instruments and singing. Read Full Bio\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/profile.php?id=100077694755838&mibextid=ZbWKwL\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/auhona-islam-429822208\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/auhona\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Check String in Bash - LinuxSimply","description":"In Bash, checking strings' various features like if they are empty, equal, or substring matching is crucial to manipulating strings.","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:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/","og_locale":"en_US","og_type":"article","og_title":"Check String in Bash - LinuxSimply","og_description":"In Bash, checking strings' various features like if they are empty, equal, or substring matching is crucial to manipulating strings.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/profile.php?id=100077694755838&mibextid=ZbWKwL","article_published_time":"2024-01-28T10:02:32+00:00","article_modified_time":"2024-04-01T06:46:05+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/6.-Feature-image.png","type":"image\/png"}],"author":"Auhona Islam","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Auhona Islam","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/"},"author":{"name":"Auhona Islam","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/25a3d16db4655804617c9e0c4a7989fb"},"headline":"Check String in Bash","datePublished":"2024-01-28T10:02:32+00:00","dateModified":"2024-04-01T06:46:05+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/"},"wordCount":1059,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/6.-Feature-image.png","keywords":["bash string"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/","name":"Check String in Bash - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/6.-Feature-image.png","datePublished":"2024-01-28T10:02:32+00:00","dateModified":"2024-04-01T06:46:05+00:00","description":"In Bash, checking strings' various features like if they are empty, equal, or substring matching is crucial to manipulating strings.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/6.-Feature-image.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/6.-Feature-image.png","width":400,"height":400,"caption":"Check string in Bash."},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/check-string\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/linuxsimply.com\/"},{"@type":"ListItem","position":2,"name":"Bash Scripting Tutorial","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/"},{"@type":"ListItem","position":3,"name":"Bash String","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/"},{"@type":"ListItem","position":4,"name":"Check String in Bash"}]},{"@type":"WebSite","@id":"https:\/\/linuxsimply.com\/#website","url":"https:\/\/linuxsimply.com\/","name":"LinuxSimply","description":"All About Linux","publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/linuxsimply.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/linuxsimply.com\/#organization","name":"LinuxSimply","url":"https:\/\/linuxsimply.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","width":355,"height":48,"caption":"LinuxSimply"},"image":{"@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/25a3d16db4655804617c9e0c4a7989fb","name":"Auhona Islam","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Auhona-Islam-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Auhona-Islam-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Auhona-Islam-II-96x96.png","caption":"Auhona Islam"},"description":"Auhona Islam is a dedicated professional with a background in Electronics and Communication Engineering (ECE) from Khulna University of Engineering &amp; Technology. Graduating in 2023, Auhona is currently excelling in her role as a Linux content developer executive at SOFTEKO to provide a more straightforward route for Linux users. She aims to generate compelling materials for Linux users with her knowledge and skills. She holds her enthusiasm in the realm of Machine Learning (ML), Deep Learning (DL), and Artificial Intelligence (AI). Apart from these, she has a passion for playing instruments and singing. Read Full Bio","sameAs":["https:\/\/www.facebook.com\/profile.php?id=100077694755838&mibextid=ZbWKwL","https:\/\/www.linkedin.com\/in\/auhona-islam-429822208"],"url":"https:\/\/linuxsimply.com\/author\/auhona\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/35251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/users\/314912"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=35251"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/35251\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/35258"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=35251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=35251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=35251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}