{"id":36359,"date":"2024-02-11T12:16:29","date_gmt":"2024-02-11T12:16:29","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=36359"},"modified":"2024-03-31T06:09:11","modified_gmt":"2024-03-31T06:09:11","slug":"bash-string-to-int","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/","title":{"rendered":"How to Convert a Bash String to Int? [8 Methods]"},"content":{"rendered":"<p style=\"text-align: justify;\">In bash scripting, the conversion of the string is important for arithmetic operations. You can not perform the arithmetic operations on the string representation numbers. Also, the string conversion is important for data validation, comparison, and formatting output. So, for effective and efficient scripting, a clear concept of how to convert a bash string to int (integer) is essential.<\/p>\n<p style=\"text-align: justify;\">To convert a string into an int( integer) in bash, check the following methods:<\/p>\n<ol>\n<li>Using arithmetic expansion operator: <code class=\"\" data-line=\"\">$((input_string))<\/code><\/li>\n<li>Using the expr command: <code class=\"\" data-line=\"\">expr EXPRESSION<\/code><\/li>\n<li>Using the let command: <code class=\"\" data-line=\"\">let EXPRESSION<\/code><\/li>\n<li>Using the bc command: <code class=\"\" data-line=\"\">echo &quot;expression&quot; | bc [options]<\/code><\/li>\n<li>Using the awk command:\u00a0 <code class=\"\" data-line=\"\">echo &quot;input_str&quot; | awk &#039;pattern { action }&#039;<\/code><\/li>\n<li>Using the perl command: <code class=\"\" data-line=\"\">perl [options] -e &#039;action&#039;<\/code><\/li>\n<li>Using a loop with conditional statements<\/li>\n<li>Using the python command: <code class=\"\" data-line=\"\">python3 [option] {action}<\/code>.<\/li>\n<\/ol>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Practice_Files-Convert_a_String_to_Integer_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 Convert String To Integer in Bash<\/span><\/a><\/div>\n<p style=\"text-align: justify;\">Dive into the article to learn these methods of how to convert a bash string to an integer in detail.<\/p>\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\/manipulation\/string-to-int\/#1_Using_the_%E2%80%9C%E2%80%A6%E2%80%9D_Arithmetic_Expansion_Operator\" >1. Using the \u201c$((\u2026))\u201d Arithmetic Expansion Operator<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#Mixing_Another_String_in_the_Expression\" >Mixing Another String in the Expression<\/a><\/li><\/ul><\/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\/manipulation\/string-to-int\/#2_Using_the_%E2%80%9Cexpr%E2%80%9D_Command\" >2. Using the \u201cexpr\u201d Command<\/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\/manipulation\/string-to-int\/#3_Using_the_%E2%80%9Clet%E2%80%9D_Command\" >3. Using the \u201clet\u201d Command<\/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\/manipulation\/string-to-int\/#4_Using_the_%E2%80%9Cbc%E2%80%9D_Command\" >4. Using the \u201cbc\u201d Command<\/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\/manipulation\/string-to-int\/#5_Using_the_%E2%80%9Cawk%E2%80%9D_Command\" >5. Using the \u201cawk\u201d Command<\/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\/manipulation\/string-to-int\/#6_Using_the_%E2%80%9Cperl%E2%80%9D_Command\" >6. Using the \u201cperl\u201d Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#7_Using_a_Loop_to_Convert_a_String_to_an_Integer\" >7. Using a Loop to Convert a String to an Integer<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#8_Using_%E2%80%9Cpython%E2%80%9D_to_Convert_a_String_to_an_Integer\" >8. Using \u201cpython\u201d to Convert a String to an Integer<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#Bonus_Convert_a_Mixed_String_to_an_Integer\" >Bonus: Convert a Mixed String to an Integer<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#Practice_Tasks_to_Convert_a_String_to_an_Intinteger\" >Practice Tasks to Convert a String to an Int(integer)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#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-14\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#Why_should_you_convert_strings_to_Integer\" >Why should you convert strings to Integer?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#How_to_convert_an_empty_string_to_int_bash\" >How to convert an empty string to int bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#How_to_convert_int_to_string_in_a_shell_script\" >How to convert int to string in a shell script?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"1_Using_the_%E2%80%9C%E2%80%A6%E2%80%9D_Arithmetic_Expansion_Operator\"><\/span>1. Using the \u201c$((\u2026))\u201d Arithmetic Expansion Operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">To convert a string into an integer, you can use the <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/expansion\/arithmetic-expansion\/\" target=\"_blank\" rel=\"noopener\"><strong>arithmetic expansion<\/strong><\/a> operator <code class=\"\" data-line=\"\">$((\u2026))<\/code>. In bash scripting, the arithmetic expansion operator is a simple but very powerful tool for performing calculations and manipulation of numerical values. This operator only works on the integer value. The <strong>$((\u2026))<\/strong> interprets the expression within the parentheses as an arithmetic expression. If the expression contains the pure numerical string, then the operator converts the string into an integer and performs the expression. Check the script below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# String containing a number\nstring_number=&quot;42&quot;\n\n# Convert string to an integer using arithmetic expansion\ninteger_result=$((string_number))\n\n# Print the result\necho &quot;Original String: $string_number&quot;\necho &quot;Converted Integer: $integer_result&quot;<\/code><\/pre>\n<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\">\n<p style=\"text-align: justify;\">At first, the script declares the input string in a variable named <code class=\"\" data-line=\"\">string_number<\/code>. The <code class=\"\" data-line=\"\">integer_result=$((string_number))<\/code> syntax converts the string to its integer value. At last, the <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/output\/echo-command\/\" target=\"_blank\" rel=\"noopener\"><strong>echo command<\/strong><\/a> prints the converted integer value in the terminal.<\/div><\/div>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-36365 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/1.-Arithmetic-expansion.png\" alt=\"Using the arithmetic expansion the string has been converted into int\" width=\"700\" height=\"169\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/1.-Arithmetic-expansion.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/1.-Arithmetic-expansion-300x72.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>The image shows the script has converted the input string \u201c42\u201d which contains two characters \u201c4\u201d and \u201c2\u201d into integer value<strong> 42.<\/strong><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Mixing_Another_String_in_the_Expression\"><\/span>Mixing Another String in the Expression<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">If you try to add a pure numeric string with another character string inside the arithmetic operator then it will only show the integer value. Take a look at the following script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# String containing a number\nstring_number=&quot;42+Hello&quot;\n\n# Convert string to an integer using arithmetic expansion\ninteger_result=$((string_number))\n\n# Print the result\necho &quot;Original String: $string_number&quot;\necho &quot;Converted Integer: $integer_result&quot;<\/code><\/pre>\n<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\">\n<p style=\"text-align: justify;\">In the variable<code class=\"\" data-line=\"\">string_number<\/code>, the script adds a character string with a numerical string. Then with <code class=\"\" data-line=\"\">integer_result=$((string_number)) syntax<\/code>, the script will convert the numeric string into its integer value.<\/div><\/div>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-36372 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/2.-Special.png\" alt=\"Convert a string of character and number into int\" width=\"653\" height=\"239\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/2.-Special.png 653w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/2.-Special-300x110.png 300w\" sizes=\"(max-width: 653px) 100vw, 653px\" \/><\/p>\n<p>The output shows that the script has only converted the numerical string into the integer value.<\/p>\n<div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#e8f9fc;border-color:#ffffff;color:#333333;\"><strong>Note: <\/strong>This only performs on the nonspace string and also on the string that does not contain a special character. If you use a string that contains a special character or space then it will return an error message.<\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"2_Using_the_%E2%80%9Cexpr%E2%80%9D_Command\"><\/span>2. Using the \u201cexpr\u201d Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">To convert a bash string into an integer, you can use the <strong>expr command<\/strong>. The bash script uses the expr command to evaluate expressions and manipulate strings. But you can also use the following command for converting a string into an integer by adding a numerical value to the input string:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# String containing a number\nstring_number=&quot;42&quot;\n\n# Convert string to integer using expr\ninteger_result=$(expr &quot;$string_number&quot; + 0)\n\n# Print the result\necho &quot;Original String: $string_number&quot;\necho &quot;Converted Integer: $integer_result&quot;<\/code><\/pre>\n<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\">\n<p style=\"text-align: justify;\">Firstly the script declares a number as a string in a variable named <code class=\"\" data-line=\"\">string_number<\/code>.\u00a0 Then in<code class=\"\" data-line=\"\">integer_number=$(expr &quot;$string_number&quot; + 0)<\/code>the <strong>expr<\/strong> command converts the string into a number. Adding<code class=\"\" data-line=\"\">0<\/code>with the string forces bash to interpret the string as an integer and perform the arithmetic expression. Later, the <strong>echo <\/strong>command prints the string as a number into the terminal.<\/div><\/div>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-36408 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/3.-expr-1.png\" alt=\"Using the expr command, a string has been converted to int\" width=\"638\" height=\"212\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/3.-expr-1.png 638w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/3.-expr-1-300x100.png 300w\" sizes=\"(max-width: 638px) 100vw, 638px\" \/><\/p>\n<p style=\"text-align: justify;\">The output shows the expr command converts the original string \u201c123\u201d into integer value <strong>123<\/strong>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"3_Using_the_%E2%80%9Clet%E2%80%9D_Command\"><\/span>3. Using the \u201clet\u201d Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In bash scripting, the <strong>let command<\/strong> evaluates the arithmetic operations and assignments. The command performs the expression that the script declares after it.<\/p>\n<p style=\"text-align: justify;\">To convert the bash string into an integer using the <code class=\"\" data-line=\"\">let<\/code> command, take a look at the following script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# String containing a number\nstring_number=&quot;9876&quot;\n\n# Use the let command to convert the string to an integer\nlet &quot;integer_result=$string_number&quot;\n\n# Print the result\necho &quot;Original String: $string_number&quot;\necho &quot;Converted Integer: $integer_result&quot;<\/code><\/pre>\n<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\">\n<p style=\"text-align: justify;\">The <code class=\"\" data-line=\"\">let &quot;integer_result=$string_number&quot;<\/code> syntax converts the string number to its integer value by using the <code class=\"\" data-line=\"\">let command<\/code>.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-36409 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/4.-let.png\" alt=\"The string has been converted into integer using the let command\" width=\"609\" height=\"204\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/4.-let.png 609w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/4.-let-300x100.png 300w\" sizes=\"(max-width: 609px) 100vw, 609px\" \/><\/p>\n<p style=\"text-align: justify;\">The image shows that the script <strong>let.sh<\/strong> has successfully converted the string \u201c9876\u201d into its integer value <strong>9876<\/strong>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"4_Using_the_%E2%80%9Cbc%E2%80%9D_Command\"><\/span>4. Using the \u201cbc\u201d Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">To convert a bash string into an integer you can use the <a href=\"https:\/\/linuxsimply.com\/bc-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>bc command<\/strong><\/a>. The bash script uses the external command <strong>bc<\/strong> as a calculator that evaluates the arithmetic expression. In this method, you need to pipe the input to the bc command and then the <code class=\"\" data-line=\"\">bc<\/code> command evaluates the input. Check the following script:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# String containing a number\nstring_number=&quot;789&quot;\n\n# Use bc to evaluate the string as an arithmetic expression\ninteger_result=$(echo &quot;$string_number&quot; | bc)\n\n# Print the result\necho &quot;Original String: $string_number&quot;\necho &quot;Converted Integer: $integer_result&quot;<\/code><\/pre>\n<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\">\n<p style=\"text-align: justify;\">Firstly the script declares a string in a variable named <code class=\"\" data-line=\"\">string_number<\/code>. Then in <code class=\"\" data-line=\"\">integer_result=$(echo &quot;$string_number&quot; | bc)<\/code>, the<a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/redirection-and-piping\/piping\/\" target=\"_blank\" rel=\"noopener\"><strong> pipe (|) <\/strong><\/a>operator redirects the output of the echo command to the <code class=\"\" data-line=\"\">bc<\/code> command. The bc command converts the string number into an integer value.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-36419 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/5.-bc.png\" alt=\"Converting the input string into integer in bash\" width=\"591\" height=\"208\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/5.-bc.png 591w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/5.-bc-300x106.png 300w\" sizes=\"(max-width: 591px) 100vw, 591px\" \/><\/p>\n<p>The output shows the bc command converts the original string \u201c789\u201d into its integer value <strong>789<\/strong>.<\/p>\n<div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#e8f9fc;border-color:#ffffff;color:#333333;\"><strong>Note: <\/strong>By using this method you can convert a pure numeric string into a number. It converts the integer string and a floating point string into an integer and floating point number respectively.<\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"5_Using_the_%E2%80%9Cawk%E2%80%9D_Command\"><\/span>5. Using the \u201cawk\u201d Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In bash scripting, the awk is a versatile command tool used for text processing and string manipulation. Using the int function, the <a href=\"https:\/\/linuxsimply.com\/awk-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>awk command<\/strong><\/a> converts the numeric string into its integer value.<\/p>\n<p style=\"text-align: justify;\">To convert a string into an integer by using the <code class=\"\" data-line=\"\">awk<\/code> command, follow the script below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# String containing a number\nstring_number=&quot;456&quot;\n\n# Use awk to extract the numerical value\ninteger_result=$(echo &quot;$string_number&quot; | awk &#039;{print int($1)}&#039;)\n\n# Print the result\necho &quot;Original String: $string_number&quot;\necho &quot;Converted Integer: $integer_result&quot;<\/code><\/pre>\n<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\">\n<p style=\"text-align: justify;\">With the<code class=\"\" data-line=\"\">$(echo &quot;$string_number&quot; | awk &#039;{print int($1)}&#039;)<\/code>the script extracts the integer value to its integer value and stores the output in a variable named <code class=\"\" data-line=\"\">integer_result<\/code>. The <code class=\"\" data-line=\"\">pipe operator<\/code> takes the output to the <code class=\"\" data-line=\"\">awk<\/code> command. The <code class=\"\" data-line=\"\">int($1)<\/code> syntax takes the first argument of the input and the awk command converts the first argument into an integer value using the <strong>int() function<\/strong>. The print action within the <code class=\"\" data-line=\"\">awk<\/code> command prints the converted output and later the script stores the output in<code class=\"\" data-line=\"\">integer_result<\/code>variable.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-36432 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/6.-awk.sh_.png\" alt=\"Using the awk command convert the string into integer in bash\" width=\"624\" height=\"192\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/6.-awk.sh_.png 624w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/6.-awk.sh_-300x92.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/p>\n<p>The image shows that the<code class=\"\" data-line=\"\">awk<\/code>command has converted the original string \u201c456\u201d into an integer value of <strong>456<\/strong>.<\/p>\n<p>With the awk command, you can also convert a string that contains floating point characters into an integer. Here, the script only converts the integer part of the given string. For example, if you input a string in a variable named string_number=&#8221;456.1234&#8243; then it will output the integer part of the string which is <strong>456<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-36433 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/7.-awkfloat.png\" alt=\"Converted a string into integer in bash \" width=\"611\" height=\"131\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/7.-awkfloat.png 611w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/7.-awkfloat-300x64.png 300w\" sizes=\"(max-width: 611px) 100vw, 611px\" \/><\/p>\n<p>As you can see the script successfully converts the string into an integer value.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"6_Using_the_%E2%80%9Cperl%E2%80%9D_Command\"><\/span>6. Using the \u201cperl\u201d Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">To convert a string into an integer value you can use the <code class=\"\" data-line=\"\">perl<\/code> command. Like the<code class=\"\" data-line=\"\">awk<\/code>command, the <strong>perl<\/strong> uses the <code class=\"\" data-line=\"\">int()<\/code> function to convert a string into an integer. Follow the script below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# String containing a number\nstring_number=&quot;123&quot;\n\n# Use perl to convert the string to an integer\ninteger_result=$(perl -e &quot;print int(&#039;$string_number&#039;)&quot;)\n\n# Print the result\necho &quot;Original String: $string_number&quot;\necho &quot;Converted Integer: $integer_result&quot;<\/code><\/pre>\n<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\">\n<p style=\"text-align: justify;\">Within the <code class=\"\" data-line=\"\">$(perl -e &quot;print int(&#039;$string_number&#039;)&quot;)<\/code>, the <code class=\"\" data-line=\"\">perl -e<\/code> executes a perl expression in the script. Then the int function converts the string value to an integer value. The <code class=\"\" data-line=\"\">&quot;print int(&#039;$string_number&#039;)&quot;<\/code> prints the integer value of the string_number.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-36434 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/8.-perl.png\" alt=\"Converting the string into integer\" width=\"653\" height=\"212\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/8.-perl.png 653w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/8.-perl-300x97.png 300w\" sizes=\"(max-width: 653px) 100vw, 653px\" \/><\/p>\n<p style=\"text-align: justify;\">From the image you can see, that the original string is \u201c123\u201d which means three characters \u201c1\u201d, \u201c2\u201d and \u201c3\u201d and the converted output is an integer value of <strong>123.\u00a0 <\/strong><\/p>\n<p>As for the perl command, it can also convert the integer part of the floating point string into an integer. Here is how it looks:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-36435 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/9.-perlfloat.png\" alt=\"Converting the floating point string into integer in bash\" width=\"612\" height=\"137\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/9.-perlfloat.png 612w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/9.-perlfloat-300x67.png 300w\" sizes=\"(max-width: 612px) 100vw, 612px\" \/><\/p>\n<p>So, the script has converted the integer part which is <strong>123<\/strong> of the input string into an integer.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"7_Using_a_Loop_to_Convert_a_String_to_an_Integer\"><\/span>7. Using a Loop to Convert a String to an Integer<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Without using any specific command, you can convert a string into an integer using a <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/loop\/\"><strong>loop<\/strong><\/a>. In bash scripting, a loop allows a block of code that executes repeatedly for a set of specified values or conditions.<\/p>\n<p>To convert a bash string into an int value, check the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# String containing a number\nstring_number=&quot;12345&quot;\n\n# Initialize the integer result\ninteger_result=0\n\n# Iterate over each character in the string\nfor ((i = 0; i &lt; ${#string_number}; i++)); do\n# Get the current character\ncurrent_char=&quot;${string_number:$i:1}&quot;\n\n# Check if the character is a digit\nif [[ &quot;$current_char&quot; =~ [0-9] ]]; then\n# Multiply the current result by 10 and add the digit\ninteger_result=$((integer_result * 10 + current_char))\nelse\n# Handle non-digit characters if needed\necho &quot;Non-digit character found: $current_char&quot;\nfi\ndone\n\n# Print the result\necho &quot;Original String: $string_number&quot;\necho &quot;Converted Integer: $integer_result&quot;<\/code><\/pre>\n<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\">\n<p style=\"text-align: justify;\">At first, the script declares a string in a variable named <code class=\"\" data-line=\"\">string_number<\/code>. After that, the script initializes an integer value to <strong>0 <\/strong>in a variable named<code class=\"\" data-line=\"\">integer_result<\/code>. The <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/loop\/for-loop\/\" target=\"_blank\" rel=\"noopener\"><strong>for loop<\/strong><\/a> iterates over each character in the<code class=\"\" data-line=\"\">string_number<\/code>variable. The iteration continues until the value of<code class=\"\" data-line=\"\">i<\/code>is equal to or greater than the length of the string. The <strong>conditional statement<\/strong> checks whether the extracted character is a digit or not. If the character is a digit then the script performs multiplication and addition to convert the string to its integer value. If the string does not contain digits then the script executes the <strong>else block<\/strong>.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-36438 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/10.-loop.png\" alt=\"Converting the string into integer using loop\" width=\"700\" height=\"178\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/10.-loop.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/10.-loop-300x76.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>The output shows the loop has converted the original string 12345 into an integer value <strong>12345.<\/strong><\/p>\n<h2><span class=\"ez-toc-section\" id=\"8_Using_%E2%80%9Cpython%E2%80%9D_to_Convert_a_String_to_an_Integer\"><\/span>8. Using \u201cpython\u201d to Convert a String to an Integer<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">To convert a string into an integer you can use the <code class=\"\" data-line=\"\">python<\/code> command. While using the Python command you need to use the the action within quotes. Here is how:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# String containing a number\nstring_number=&quot;789&quot;\n\n# Use Python to convert the string to an integer\ninteger_result=$(python3 -c &quot;print(int(float (&#039;$string_number&#039;)))&quot;)\n\n# Print the result\necho &quot;Original String: $string_number&quot;\necho &quot;Converted Integer: $integer_result&quot;<\/code><\/pre>\n<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\">\n<p style=\"text-align: justify;\">Within the python3 command, <code class=\"\" data-line=\"\">int(float (&#039;$string_number&#039;)))<\/code> converts the input string whether it is an integer string or floating point number into an integer. Then the <strong>echo command<\/strong> prints the modified output.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-36454 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/python.png\" alt=\"Convert the string into integer using python command\" width=\"620\" height=\"139\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/python.png 620w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/python-300x67.png 300w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/p>\n<p>From the image, you can see the script has converted the input string \u201c789\u201d into an integer value of <strong>789<\/strong>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Bonus_Convert_a_Mixed_String_to_an_Integer\"><\/span>Bonus: Convert a Mixed String to an Integer<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">While converting a string that includes not only digits but also characters, it won\u2019t show the expected result if you try to apply the pure bash scripting(arithmetic operator, loop) or external commands(<strong>awk, perl, let, bc<\/strong>). For this type of string, firstly you need to extract the digits from the string and then convert the string to an integer.<\/p>\n<ol>\n<li>To convert a string that contains both characters and digits into an integer value using bash scripting, check out the following script:\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# String containing digits and characters\nmixed_string=&quot;123 abc 456 def&quot;\n\n# Remove non-digit characters using tr command\ndigits_only=$(echo &quot;$mixed_string&quot; | tr -cd &#039;[:digit:]&#039;)\n\n# Convert the resulting string to an integer using arithmetic expansion\ninteger_result=$((digits_only))\n\n# Print the result\necho &quot;Original String: $mixed_string&quot;\necho &quot;Converted Integer: $integer_result&quot;<\/code><\/pre>\n<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\">\n<p style=\"text-align: justify;\">At first, the script declares a string in a variable named <code class=\"\" data-line=\"\">mixed_string<\/code>. After that, the pipe operator redirects the output of the <code class=\"\" data-line=\"\">echo<\/code> command to the <code class=\"\" data-line=\"\">tr<\/code> command. Using the <strong>-c option<\/strong> the <a href=\"https:\/\/linuxsimply.com\/tr-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>tr command <\/strong><\/a>finds the complement of the matched character here the matched characters are the digits and then deletes the complementary characters using the <strong>-d option<\/strong>. At last, the script uses the arithmetic expansion operator to convert the extracted output which contains only digits to an integer value.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-36443 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/12.-mixed-to-int.png\" alt=\"Convert the mixed string into integer\" width=\"825\" height=\"164\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/12.-mixed-to-int.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/12.-mixed-to-int-300x60.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/12.-mixed-to-int-768x153.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p>The image shows the script successfully extracted the numerical value from the string and converted it to an integer.<\/li>\n<li>To convert a string that contains both characters and digits into an integer value in bash using <code class=\"\" data-line=\"\">awk<\/code> command, take a look at the following script:\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Example string containing non-numerical characters\nstring=&quot;abc123def&quot;\n\n# Extract numerical value using awk and print it\ndigits_only=$(echo &quot;$string&quot; | awk &#039;{ gsub(\/[^0-9]\/,&quot;&quot;,$0); print $0 }&#039;)\ninteger_result=$((digits_only))\n\necho &quot;Integer value: $integer&quot;<\/code><\/pre>\n<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\">\n<p style=\"text-align: justify;\">The <strong>pipe operator<\/strong> takes the output which is the declared string to the <code class=\"\" data-line=\"\">awk<\/code> command. Using <code class=\"\" data-line=\"\">&#039;{ gsub(\/[^0-9]\/,&quot;&quot;,$0); print $0 }&#039;<\/code> the <strong>awk command<\/strong> finds and replaces all the occurrences of the non-digit characters(<strong>[^0-9]<\/strong>) with the empty string(<strong>&#8220;&#8221;<\/strong>) and stores the modified string in an<code class=\"\" data-line=\"\">integer<\/code>variable.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-36444 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/13.-mixed-to-int-withoutspace.png\" alt=\"Using awk command, convert the mixed string into integer\" width=\"700\" height=\"120\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/13.-mixed-to-int-withoutspace.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/13.-mixed-to-int-withoutspace-300x51.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p style=\"text-align: justify;\">The output shows the extracted and converted integer value of the input string.<\/p>\n<\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Practice_Tasks_to_Convert_a_String_to_an_Intinteger\"><\/span>Practice Tasks to Convert a String to an Int(integer)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ol>\n<li>Convert the string \u201c8889\u201d into its integer value Using the following command:\n<ul>\n<li>awk command<\/li>\n<li>bc command<\/li>\n<\/ul>\n<\/li>\n<li>Convert the mixed string into an integer by extracting digits using the expr command: input_string=\u201ctuyt123 4764 hgh\u201d<\/li>\n<li>Convert the mixed string into an integer value using the perl command: input_string=\u201ctuyt123 4764 hgh\u201d<\/li>\n<\/ol>\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;\">The article shows different methods to convert both the simple pure numeric string and mixed string to an integer. Among all the methods, if you want to use the pure bash script method to simply convert a string into an integer then you can use the arithmetic expansion operator and loops. Otherwise, use the external command which provides versatility. Hope this article helps you to learn how to convert a bash string.<\/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=\"Why_should_you_convert_strings_to_Integer\"><\/span>Why should you convert strings to Integer?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To perform arithmetic operations on the string which contains numbers, you need to convert the string to an integer. The other reasons for the conversion are data processing, data validation, and data comparison.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_convert_an_empty_string_to_int_bash\"><\/span>How to convert an empty string to int bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To convert an empty string to an integer you can use parameter expansion. Inside the parameter expansion, if the input string is empty or not set then it automatically uses the default value which is <code class=\"\" data-line=\"\">0<\/code>. Here the script looks:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Define the string\nempty_string=&quot;&quot;\n\n# Convert the empty string to an integer with a default value of 0\ninteger_result=${empty_string:-0}\n\n# Print the result\necho &quot;Original String: $empty_string&quot;\necho &quot;Converted Integer: $integer_result&quot;\n\n#Original String:\n#Converted Integer: 0<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"How_to_convert_int_to_string_in_a_shell_script\"><\/span>How to convert int to string in a shell script?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To convert an integer to a string you can use <strong>parameter expansion<\/strong> and <strong>command substitution<\/strong>. Inside the quote, use the dollar sign<code class=\"\" data-line=\"\">$<\/code>as a prefix following the input integer string. Then it will convert the integer into a string. Follow the script below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Define an integer\ninteger_variable=123\n\n# Convert the integer to a string using parameter expansion\nstring_result=&quot;$integer_variable&quot;\n\n# Print the result\necho &quot;Original Integer: $integer_variable&quot;\necho &quot;Converted String: $string_result&quot;\n\n#Original Integer: 123\n#Converted String: 123<\/code><\/pre>\n<p><script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": {\n    \"@type\": \"Question\",\n    \"name\": \"Why should you convert strings to Integer?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"To perform arithmetic operations on the string which contains numbers, you need to convert the string to an integer. The other reasons for the conversion are data processing, data validation, and data comparison.\"\n    }\n  }\n}\n<\/script><\/p>\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\/manipulation\/format-string\/\" target=\"_blank\" rel=\"noopener\">How to Format a String in Bash? [Methods, Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/convert-to-uppercase\/\" target=\"_blank\" rel=\"noopener\">How to Convert Bash String to Uppercase? [7 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/bash-to-lowercase\/\" target=\"_blank\" rel=\"noopener\">How to Convert Bash String to Lowercase? [7 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-replace\/\" target=\"_blank\" rel=\"noopener\">How to Replace String in Bash? [5 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/trim-string\/\" target=\"_blank\" rel=\"noopener\">How to Trim String in Bash? [6 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/truncate-string\/\" target=\"_blank\" rel=\"noopener\">How to Truncate String in Bash? [5 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/remove-character\/\" target=\"_blank\" rel=\"noopener\">How to Remove Character from String in Bash? [7+ Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/remove-first-character\/\" target=\"_blank\" rel=\"noopener\">How to Remove First Character From Bash String? [7 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/remove-last-character\/\" target=\"_blank\" rel=\"noopener\">How to Remove Last Character from Bash String [6 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-functions\/\" target=\"_blank\" rel=\"noopener\">How to Use String Functions in Bash? [Examples Included]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/generate-random-string\/\" target=\"_blank\" rel=\"noopener\">How to Generate a Random String in Bash? [8 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-array\/\" target=\"_blank\" rel=\"noopener\">How to Manipulate Bash String Array [5 Ways]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/here-string\/\" target=\"_blank\" rel=\"noopener\">How to Use \u201cHere String\u201d in Bash? [Basic to Advance]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/base64-encode-decode\/\" target=\"_blank\" rel=\"noopener\">Encode and Decode with \u201cbase64\u201d in Bash [6 Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/bash-eval\/\" target=\"_blank\" rel=\"noopener\">How to Use \u201ceval\u201d Command in Bash? [8 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/get-first-character\/\" target=\"_blank\" rel=\"noopener\">How to Get the First Character from Bash String? [8 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;String Manipulation in Bash&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\/manipulation\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/\" target=\"_blank\" rel=\"noopener\">String Manipulation in Bash<\/a><\/span> | <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;36359&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;How to Convert a Bash String to Int? [8 Methods]&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 scripting, the conversion of the string is important for arithmetic operations. You can not perform the arithmetic operations &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Convert a Bash String to Int? [8 Methods]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#more-36359\" aria-label=\"Read more about How to Convert a Bash String to Int? [8 Methods]\">Read more<\/a><\/p>\n","protected":false},"author":314907,"featured_media":36455,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[192],"class_list":["post-36359","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-string-manipulation","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>How to Convert a Bash String to Int? [8 Methods] - LinuxSimply<\/title>\n<meta name=\"description\" content=\"Explore the article to get a clear concept of how to convert a bash string to int. And enhance your knowledge in efficient scripting.\" \/>\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\/manipulation\/string-to-int\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Convert a Bash String to Int? [8 Methods] - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"Explore the article to get a clear concept of how to convert a bash string to int. And enhance your knowledge in efficient scripting.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/afia.zahin.7796?mibextid=ZbWKwL\" \/>\n<meta property=\"article:published_time\" content=\"2024-02-11T12:16:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-31T06:09:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Bash.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=\"Afia Zahin Oishi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Afia Zahin Oishi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 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\\\/manipulation\\\/string-to-int\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/manipulation\\\/string-to-int\\\/\"},\"author\":{\"name\":\"Afia Zahin Oishi\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/2afb5d809ba746cd33b77eb2639949d7\"},\"headline\":\"How to Convert a Bash String to Int? [8 Methods]\",\"datePublished\":\"2024-02-11T12:16:29+00:00\",\"dateModified\":\"2024-03-31T06:09:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/manipulation\\\/string-to-int\\\/\"},\"wordCount\":2241,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/manipulation\\\/string-to-int\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/Bash.png\",\"keywords\":[\"string manipulation\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/manipulation\\\/string-to-int\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/manipulation\\\/string-to-int\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/manipulation\\\/string-to-int\\\/\",\"name\":\"How to Convert a Bash String to Int? [8 Methods] - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/manipulation\\\/string-to-int\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/manipulation\\\/string-to-int\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/Bash.png\",\"datePublished\":\"2024-02-11T12:16:29+00:00\",\"dateModified\":\"2024-03-31T06:09:11+00:00\",\"description\":\"Explore the article to get a clear concept of how to convert a bash string to int. And enhance your knowledge in efficient scripting.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/manipulation\\\/string-to-int\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/manipulation\\\/string-to-int\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/manipulation\\\/string-to-int\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/Bash.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/Bash.png\",\"width\":400,\"height\":400,\"caption\":\"bash string to int\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/manipulation\\\/string-to-int\\\/#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\":\"String Manipulation in Bash\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/manipulation\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to Convert a Bash String to Int? [8 Methods]\"}]},{\"@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\\\/2afb5d809ba746cd33b77eb2639949d7\",\"name\":\"Afia Zahin Oishi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Afia-Zahin-Oishi-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Afia-Zahin-Oishi-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Afia-Zahin-Oishi-II-96x96.png\",\"caption\":\"Afia Zahin Oishi\"},\"description\":\"Assalamualaikum, I am Afia Zahin, completed my graduation in Biomedical Engineering from Bangladesh University of Engineering and Technology, currently working as a Linux Content Developer Executive at SOFTEKO. A high achieving professional with a strong work ethic and able to work in a team in order to consistently achieve my goal and build my skillset. Able to handle difficult problems with patience and swift decision-making. Read Full Bio\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/afia.zahin.7796?mibextid=ZbWKwL\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/afia-zahin-oishi-5b4616288\\\/\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/oishi\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Convert a Bash String to Int? [8 Methods] - LinuxSimply","description":"Explore the article to get a clear concept of how to convert a bash string to int. And enhance your knowledge in efficient scripting.","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\/manipulation\/string-to-int\/","og_locale":"en_US","og_type":"article","og_title":"How to Convert a Bash String to Int? [8 Methods] - LinuxSimply","og_description":"Explore the article to get a clear concept of how to convert a bash string to int. And enhance your knowledge in efficient scripting.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/afia.zahin.7796?mibextid=ZbWKwL","article_published_time":"2024-02-11T12:16:29+00:00","article_modified_time":"2024-03-31T06:09:11+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Bash.png","type":"image\/png"}],"author":"Afia Zahin Oishi","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Afia Zahin Oishi","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/"},"author":{"name":"Afia Zahin Oishi","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/2afb5d809ba746cd33b77eb2639949d7"},"headline":"How to Convert a Bash String to Int? [8 Methods]","datePublished":"2024-02-11T12:16:29+00:00","dateModified":"2024-03-31T06:09:11+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/"},"wordCount":2241,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Bash.png","keywords":["string manipulation"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/","name":"How to Convert a Bash String to Int? [8 Methods] - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Bash.png","datePublished":"2024-02-11T12:16:29+00:00","dateModified":"2024-03-31T06:09:11+00:00","description":"Explore the article to get a clear concept of how to convert a bash string to int. And enhance your knowledge in efficient scripting.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Bash.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/02\/Bash.png","width":400,"height":400,"caption":"bash string to int"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/string-to-int\/#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":"String Manipulation in Bash","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/manipulation\/"},{"@type":"ListItem","position":5,"name":"How to Convert a Bash String to Int? [8 Methods]"}]},{"@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\/2afb5d809ba746cd33b77eb2639949d7","name":"Afia Zahin Oishi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Afia-Zahin-Oishi-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Afia-Zahin-Oishi-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Afia-Zahin-Oishi-II-96x96.png","caption":"Afia Zahin Oishi"},"description":"Assalamualaikum, I am Afia Zahin, completed my graduation in Biomedical Engineering from Bangladesh University of Engineering and Technology, currently working as a Linux Content Developer Executive at SOFTEKO. A high achieving professional with a strong work ethic and able to work in a team in order to consistently achieve my goal and build my skillset. Able to handle difficult problems with patience and swift decision-making. Read Full Bio","sameAs":["https:\/\/www.facebook.com\/afia.zahin.7796?mibextid=ZbWKwL","https:\/\/www.linkedin.com\/in\/afia-zahin-oishi-5b4616288\/"],"url":"https:\/\/linuxsimply.com\/author\/oishi\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/36359","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\/314907"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=36359"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/36359\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/36455"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=36359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=36359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=36359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}