{"id":33173,"date":"2024-01-02T09:33:55","date_gmt":"2024-01-02T09:33:55","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=33173"},"modified":"2024-02-11T06:31:11","modified_gmt":"2024-02-11T06:31:11","slug":"bash-string-concatenation","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/","title":{"rendered":"String Concatenation in Bash [6 Methods]"},"content":{"rendered":"<p style=\"text-align: justify;\">Concatenation means to join two or more elements altogether. When two strings are concatenated in a bash string, it generally refers to appending the new string to the right of the existing string. Let&#8217;s see some of the methods of bash string concatenation strings.<\/p>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/Practice-File_Bash-String-Concatenation.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 of String Concatenation 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\/operations\/concatenation\/#What_Is_Concatenation_in_Bash\" >What Is Concatenation in Bash?<\/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\/operations\/concatenation\/#6_Methods_to_Concatenate_Strings_in_Bash\" >6 Methods to Concatenate Strings in Bash<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#1_Using_the_Literal_Value_of_the_String\" >1. Using the Literal Value of the String<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#Concatenating_Multiple_Variable\" >Concatenating Multiple Variable<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#2_Using_Command_Substitution\" >2. Using Command Substitution<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#Concatenating_Two_Numbers\" >Concatenating Two Numbers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#Using_HEREDOC_to_Concatenate_Strings_in_Multiline\" >Using HEREDOC to Concatenate Strings in Multiline<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#3_Using_Parameter_Expansion\" >3. Using Parameter Expansion<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#Concatenate_String_with_Variable\" >Concatenate String with Variable<\/a><\/li><\/ul><\/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\/operations\/concatenation\/#4_Using_the_%E2%80%9C%E2%80%9D_Operator\" >4. Using the &#8220;+=&#8221; Operator<\/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\/operations\/concatenation\/#5_String_Concatenation_with_%E2%80%9Cprintf%E2%80%9D_Command\" >5. String Concatenation with &#8220;printf&#8221; Command<\/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\/operations\/concatenation\/#6_Using_Loop_to_Concatenate_Strings\" >6. Using Loop to Concatenate Strings<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#Concatenation_String_in_an_Array\" >Concatenation String in an Array<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#Practical_Examples_of_String_Concatenation\" >Practical Examples of String Concatenation<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#1_Creating_Photograph_Name\" >1. Creating Photograph Name<\/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\/operations\/concatenation\/#2_Save_Multiline_into_a_New_File\" >2. Save Multiline into a New File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#3_Constructing_Email_Addresses\" >3. Constructing Email Addresses<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#4_Generating_CSV_File\" >4. Generating CSV File<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#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-21\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#Can_I_create_log_files_using_string_concatenation\" >Can I create log files using string concatenation?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#How_to_concatenate_two_arrays_into_a_single_array\" >How to concatenate two arrays into a single array?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#How_to_concatenate_string_to_comma-separated_element\" >How to concatenate string to comma-separated element?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#How_to_insert_characters_in_a_string_in_bash\" >How to insert characters in a string in bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#Can_I_use_space_underscore_and_newline_characters_in_string_concatenation\" >Can I use space, underscore, and newline characters in string concatenation?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#Can_I_concatenate_strings_using_join\" >Can I concatenate strings using join?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"What_Is_Concatenation_in_Bash\"><\/span>What Is Concatenation in Bash?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Concatenation is merging two or more strings into a new string. Building new string, file_path, and manipulating string are the common uses of string concatenation. Concatenation is important for formatting the output of a string and for flexibility in making dynamic strings.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"6_Methods_to_Concatenate_Strings_in_Bash\"><\/span>6 Methods to Concatenate Strings in Bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In bash scripting, string concatenation is a simple task. You can do it in many ways by maintaining some basic concepts.<\/p>\n<p style=\"text-align: justify;\">In the following section, <strong>6<\/strong> <strong>easy methods<\/strong> have been mentioned to concatenate strings in bash which include using the <strong>literal<\/strong> value of the string, <strong>command substitution<\/strong>, parameter expansion, using the <strong>+=<\/strong> <strong>operator<\/strong>, <strong>printf<\/strong> command, and <strong>loop<\/strong> concatenation. Let\u2019s take a look at the methods of concatenation:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Using_the_Literal_Value_of_the_String\"><\/span>1. Using the Literal Value of the String<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The literal value of a string refers to the exact sequence of characters of the string without variable substitution or expansion. To preserve the literal value of the characters of the string, use <strong>single quotes(&#8216; &#8216;)<\/strong> which will not allow the command substitution and expansion.<\/p>\n<p>To concatenate two strings with their <strong>literal values<\/strong> use the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nconcatenated_string=&#039;Hello&#039;&#039;World&#039;\necho $concatenated_string<\/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>The line<code class=\"\" data-line=\"\">concatenated_string=&#039;Hello&#039;&#039;World&#039;<\/code>mainly concatenates the value within the single quotes and stores it in the new variable named <code class=\"\" data-line=\"\">concatenated_string<\/code>.<\/div><\/div>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-33176 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/1.-literal.png\" alt=\"Concatenate string using literal value of string\" width=\"550\" height=\"162\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/1.-literal.png 550w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/1.-literal-300x88.png 300w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/p>\n<p>From the output, you can see I have appended the literal values one after another.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Concatenating_Multiple_Variable\"><\/span>Concatenating Multiple Variable<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Using these simple literal values you can also concatenate multiple variables into a string. Here is how:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nconcatenated_string=&quot;Hello&quot;This_the_first_string&quot;World&quot;\necho &quot;$concatenated_string&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=\"\">concatenated_string=&quot;Hello&quot;This_the_first_string&quot;World&quot;<\/code>concatenates the strings and is assigned to the concatenated_string variable.<\/div><\/div>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-33177 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/2.-commands.png\" alt=\"Multiple strings are concatenated in bash\" width=\"614\" height=\"171\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/2.-commands.png 614w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/2.-commands-300x84.png 300w\" sizes=\"(max-width: 614px) 100vw, 614px\" \/><\/p>\n<p style=\"text-align: justify;\">The output shows the concatenated string. But it should be in mind that if it carries space in the string that is not inside quotes, then it will not show the expected result.<\/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;\">\n<p style=\"text-align: justify;\">To concatenate multiple strings or variables using the command substitution or parameter expansion, follow the below syntax:<\/p>\n<ol>\n<li>Command substitution:<br \/>\n<code class=\"\" data-line=\"\">string=&quot;$string1$string2$string3$string4&quot;<\/code><\/li>\n<li>Parameter Expansion:<br \/>\n<code class=\"\" data-line=\"\">string=${string1}${string2}${string3}${string4}<\/code><\/li>\n<\/ol>\n<\/div><\/div>\n<h3><span class=\"ez-toc-section\" id=\"2_Using_Command_Substitution\"><\/span>2. Using Command Substitution<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Command substitution is used to include the result of a command within another command or expression. It is denoted with <strong>$()<\/strong>. With command substitution, you can join multiple strings to create a longer string. You can also use or insert the output of a command into a string using command substitution.<\/p>\n<p>To concatenate the strings using <strong>command substitution<\/strong>, place the strings side by side. Here is how:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash \n\nstring1=&quot;The first line of the string. &quot; \nstring2=&quot;The second line of the string.&quot; string=&quot;$string1$string2&quot;\n\necho $string<\/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=\"\">&quot;$string1$string2&quot;<\/code>concatenates the string in the variables string1 and string2. The concatenated is assigned to a new variable named <code class=\"\" data-line=\"\">string<\/code>.<\/div><\/div>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-33181 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/3.-placing-strings-side-by-side.png\" alt=\"Concatenate two strings by placing side by side\" width=\"825\" height=\"158\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/3.-placing-strings-side-by-side.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/3.-placing-strings-side-by-side-300x57.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/3.-placing-strings-side-by-side-768x147.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p>Here I have concatenated two strings using command substitution and printed it on the terminal.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Concatenating_Two_Numbers\"><\/span>Concatenating Two Numbers<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">To concatenate two numbers by converting them into strings, you can use command substitution. Take a look at the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nString1=&quot;1234&quot;\nString2=&quot;4578&quot;\nString3=$String1$String2\n\necho &quot;$String3&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 value of<code class=\"\" data-line=\"\">string1<\/code>and<code class=\"\" data-line=\"\">string2<\/code>is concatenated by placing one after another using command substitution and storing the final value in <code class=\"\" data-line=\"\">string3<\/code>.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-33182 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/4.-Number.png\" alt=\"Two numbers are concatenated using command substituition\" width=\"599\" height=\"164\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/4.-Number.png 599w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/4.-Number-300x82.png 300w\" sizes=\"(max-width: 599px) 100vw, 599px\" \/><\/p>\n<p>The output shows the concatenated string of two string numbers.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Using_HEREDOC_to_Concatenate_Strings_in_Multiline\"><\/span>Using HEREDOC to Concatenate Strings in Multiline<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">Here document is a way to define multiline strings. You can use it to concatenate a string into the existing multiline string with <strong>command substitution<\/strong>.<\/p>\n<p>To concatenate strings using heredoc look at the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Initial string\noriginal_string=&quot;This is the original string.&quot;\n\n# Concatenate with another string using a here document\nnew_string=$(cat &lt;&lt;EOF\n$original_string\nThis is the additional string.\nEOF\n)\n\necho &quot;$new_string&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<code class=\"\" data-line=\"\">cat &lt;&lt;EOF<\/code>the here document has been started. In the here document, the value of the <code class=\"\" data-line=\"\">original_string<\/code>has been inserted using variable substitution. With<code class=\"\" data-line=\"\">EOF<\/code>the here doc has been ended. Using the <strong>variable substitution,<\/strong> the concatenated string has been stored in the <code class=\"\" data-line=\"\">new_string<\/code>. With the <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/input-output\/output\/echo-command\/\" target=\"_blank\" rel=\"noopener\"><strong>echo command<\/strong><\/a>, the new string has been printed.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-33191 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/5.-Heredoc1.png\" alt=\"Concatenate a string with multiline string \" width=\"686\" height=\"209\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/5.-Heredoc1.png 686w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/5.-Heredoc1-300x91.png 300w\" sizes=\"(max-width: 686px) 100vw, 686px\" \/><\/p>\n<p style=\"text-align: justify;\">In the <strong>here doc<\/strong> the first line is the original string which is declared before the heredoc starts. The additional string is also stored after the <strong>original string<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Using_Parameter_Expansion\"><\/span>3. Using Parameter Expansion<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/expansion\/parameter-expansion\/\" target=\"_blank\" rel=\"noopener\"><strong>parameter expansion<\/strong><\/a> is the process of manipulating the values of a variable. The basic syntax is <code class=\"\" data-line=\"\">${variable}<\/code> which is the variable substitution. To concatenate two or more strings you can place the string one after another using the basic syntax of the <strong>parameter expansion<\/strong>. Here is how:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\necho &quot;Using Listing&quot;\n\nstring1=&quot;The first string.&quot;\nstring2=&quot;This is a new string.&quot;\nconcatenated_string=${string1}${string2}\n\necho &quot;Concatenated String:$concatenated_string&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;\">Two strings are assigned to the <strong>string1<\/strong> and <strong>string2<\/strong> variables. The<code class=\"\" data-line=\"\">${string1}${string2}<\/code> concatenates two strings by placing the strings side by side using parameter expansion. <\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-33193 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/6.-parameter-expansion.png\" alt=\"Using parameter expansion merge two string\" width=\"825\" height=\"199\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/6.-parameter-expansion.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/6.-parameter-expansion-300x72.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/6.-parameter-expansion-768x185.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p>From the output, you can see the string is on the right side of the first string.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Concatenate_String_with_Variable\"><\/span>Concatenate String with Variable<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">To concatenate a variable with a string, you can use the <strong>parameter expansion<\/strong>. Here is how:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nString1=&quot;Hello, &quot;\nString2=&quot;${String1}World&quot;\n\necho &quot;$String2&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 first string is assigned to the <code class=\"\" data-line=\"\">string1<\/code>variable. The<code class=\"\" data-line=\"\">${String1}<\/code> is the parameter expansion. The string \u201cWorld\u201d is concatenated with the value of\u00a0 string1.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-33194 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/7.-variable-and-string.png\" alt=\"Concatenate a string and a variable\" width=\"587\" height=\"133\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/7.-variable-and-string.png 587w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/7.-variable-and-string-300x68.png 300w\" sizes=\"(max-width: 587px) 100vw, 587px\" \/><\/p>\n<p>Like the above image, you can also replace the variable with numbers or special characters.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_Using_the_%E2%80%9C%E2%80%9D_Operator\"><\/span>4. Using the &#8220;+=&#8221; Operator<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">You can use the &#8220;+=&#8221; operator for string concatenation in bash. It appends the new string to the right of the existing string.<\/p>\n<p>To concatenate two strings using the <code class=\"\" data-line=\"\">+=<\/code> operator copy the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\necho &quot;Using Simple Concatenation&quot;\n\nstring=&quot;Hello&quot;\nstring+=&quot;1234&quot;\nconcatenated_string=&quot;$string&quot;\n\necho &quot;Concatenated String:$concatenated_string&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;\">Here, the new string <strong>1234<\/strong> is concatenated after the <strong>Hello<\/strong> using the<code class=\"\" data-line=\"\">+=<\/code>operator. Without changing the existing string, the operator mainly appended the new string to the right of the existing string.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-33195 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/8.-with-operator.png\" alt=\"Concatenate two strings in bash with operator\" width=\"574\" height=\"218\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/8.-with-operator.png 574w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/8.-with-operator-300x114.png 300w\" sizes=\"(max-width: 574px) 100vw, 574px\" \/><\/p>\n<p style=\"text-align: justify;\">In this process, I have used a number as a string. If you don\u2019t want to use the double quotes while appending numbers, you can do that as there is no space between them. But it is better to use double quotes (&#8221; &#8220;).<\/p>\n<h3><span class=\"ez-toc-section\" id=\"5_String_Concatenation_with_%E2%80%9Cprintf%E2%80%9D_Command\"><\/span>5. String Concatenation with &#8220;printf&#8221; Command<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The <strong>printf command<\/strong> is mainly used for formatting the output. You can use <code class=\"\" data-line=\"\">printf<\/code> for string concatenation by formatting them and storing the output to a new string.<\/p>\n<p>To concatenation strings using <code class=\"\" data-line=\"\">printf<\/code>, use the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nstring1=&quot;Hello,&quot;\nstring2=&quot;This is a special character (*)&quot;\n\nprintf &quot;%s %s\\n&quot; &quot;$string1&quot; &quot;$string2&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;\">Two strings are declared as <strong>string1<\/strong> and <strong>string2<\/strong>. In the<code class=\"\" data-line=\"\">printf<\/code>command, the<code class=\"\" data-line=\"\">%s<\/code>is the placeholder for the string. And<code class=\"\" data-line=\"\">\\n<\/code>is used to create a new line after the output.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-33196 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/9.-printf.png\" alt=\"Two string Concatenation with printf command\" width=\"620\" height=\"159\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/9.-printf.png 620w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/9.-printf-300x77.png 300w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/p>\n<p>From the output, you can see by following this method, you can concatenate two strings one after another.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"6_Using_Loop_to_Concatenate_Strings\"><\/span>6. Using Loop to Concatenate Strings<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">You can use <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/loop\/\" target=\"_blank\" rel=\"noopener\"><strong>loop<\/strong><\/a> to concatenate a string multiple times before or after each element of the input string. At the end of the loop, you can find that the input string will contain the repetitive string.<\/p>\n<p style=\"text-align: justify;\">To concatenate a single string multiple times into an input string, you can use a <strong>loop.<\/strong> Here is how:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\ninput_string=&quot;Multiple methods of concatenation&quot;\nnewstring=&quot;&quot;\n\nfor i in $input_string\ndo\nnewstring+=&quot;Using loop $i &quot;\ndone\n\necho $newstring<\/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 <code class=\"\" data-line=\"\">input&lt;strong&gt;_&lt;\/strong&gt;string=&quot;Multiple methods of concatenation&quot;<\/code>, a new string is declared. An empty string is declared as a new string. The <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/loop\/for-loop\/\" target=\"_blank\" rel=\"noopener\"><strong>for loop<\/strong><\/a> iterates over each word of the string and concatenates &#8220;Using loop&#8221; before each word. <\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-33198 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/10.-loop.png\" alt=\"Bash string concatenation using loop\" width=\"825\" height=\"131\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/10.-loop.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/10.-loop-300x48.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/10.-loop-768x122.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p>From the above image, you can see that I have concatenated a string into another string multiple times using a loop.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Concatenation_String_in_an_Array\"><\/span>Concatenation String in an Array<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>To concatenate a string with each element of an array, follow the code shown below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\narray=(&quot;Lang1&quot; &quot;Lang2&quot; &quot;Lang3&quot;)\u00a0 # Replace with your actual values\nnew=&quot;&quot;\n\nfor i in &quot;${array[@]}&quot;\ndo\nnew+=&quot;Using loop $i... &quot;\ndone\n\necho $new<\/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;\">An array has been declared with three elements in this line<code class=\"\" data-line=\"\">array=(&quot;Lang1&quot; &quot;Lang2&quot; &quot;Lang3&quot;)<\/code>. The new_string has the concatenated string. In each iteration, the loop adds elements with the text<code class=\"\" data-line=\"\">&quot;Using loop&quot;<\/code>and stores them in the new variable.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-33200 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/11.-looparray.png\" alt=\"Concatenation of string into array using loop\" width=\"825\" height=\"135\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/11.-looparray.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/11.-looparray-300x49.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/11.-looparray-768x126.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p>By using this method, you can append a specific string after each of the strings.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Practical_Examples_of_String_Concatenation\"><\/span>Practical Examples of String Concatenation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">You can use string concatenation in several practical scenarios like constructing file names with format or types, merging multiple strings to a new file, constructing meaningful email IDs, or even generating CSV files. Here are <strong>4 examples<\/strong> to do so:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Creating_Photograph_Name\"><\/span>1. Creating Photograph Name<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To create a photograph name with format and date of modification, use the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Concatenating strings to create photo name\nfile_prefix=&quot;photo&quot;\nfile_suffix=&quot;.jpg&quot;\nfile_name=&quot;${file_prefix}_$(date +%Y%m%d)${file_suffix}&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 previous and post string has been declared with<code class=\"\" data-line=\"\"> file_prefix<\/code> and <code class=\"\" data-line=\"\">file_suffix<\/code>. With the command substitution, the <strong>date<\/strong> has been appended to the new string. The<code class=\"\" data-line=\"\">%Y%m%d<\/code>refers to the format specifier that has been used with the <a href=\"https:\/\/linuxsimply.com\/date-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>date command<\/strong><\/a> and it represents the current year, month, and date in this specific format. The character<code class=\"\" data-line=\"\">_<\/code>between the photo and date is used to concatenate the strings.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-33203 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/12.-datecreate.png\" alt=\"Using concatenation in bash create a photo name with date\" width=\"551\" height=\"165\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/12.-datecreate.png 551w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/12.-datecreate-300x90.png 300w\" sizes=\"(max-width: 551px) 100vw, 551px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Save_Multiline_into_a_New_File\"><\/span>2. Save Multiline into a New File<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To save the concatenated new multiline string which you can create using the <strong>heredoc<\/strong> into a new file, use the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\ncat &lt;&lt;EOF &gt; output.txt\nThe name of the current user is $(whoami)\nToday\u2019s date:$(date)\nEOF<\/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 <code class=\"\" data-line=\"\">cat &lt;&lt;EOF &gt; output.txt<\/code>, heredoc creates a multiline string which will be saved to the <code class=\"\" data-line=\"\">output.txt<\/code> file with the <a href=\"https:\/\/linuxsimply.com\/what-is-redirection-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>redirection<\/strong><\/a> <code class=\"\" data-line=\"\">&gt;<\/code> symbol. The heredoc has the current user name and today&#8217;s date with the help of the <a href=\"https:\/\/linuxsimply.com\/whoami-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>whoami command<\/strong><\/a> and <strong>date command<\/strong>. The EOF indicates the end of the here document.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-33205 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/13.-heredoc.png\" alt=\"Save string from heredoc into a file in bash string concatenation\" width=\"825\" height=\"222\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/13.-heredoc.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/13.-heredoc-300x81.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/13.-heredoc-768x207.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p>The <strong>output.txt<\/strong> file shows the saved output of the<strong> heredoc.sh<\/strong> script.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Constructing_Email_Addresses\"><\/span>3. Constructing Email Addresses<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To construct an email address, you can use string concatenation and also append <strong>@<\/strong> in the email address. Here is how:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Concatenating strings to construct email addresses\nuser_name=&quot;john.doe&quot;\ndomain=&quot;example.com&quot;\nemail_address=&quot;${user_name}@${domain}&quot;\n\necho &quot;Email Address: $email_address&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<code class=\"\" data-line=\"\">email_address=&quot;${user_name}@${domain}&quot;<\/code>, all the strings are previously declared, and <code class=\"\" data-line=\"\">@<\/code>is also appended by placing this at the side of the strings.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-33220 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/14.-email1.png\" alt=\"Create a email address using string concatenation\" width=\"660\" height=\"179\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/14.-email1.png 660w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/14.-email1-300x81.png 300w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_Generating_CSV_File\"><\/span>4. Generating CSV File<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To generate a CSV file, you can use string concatenation. Take a look at the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash \n\n# Concatenating strings with newline for CSV content header=&quot;Name, Age, Occupation&quot; \ndata_row1=&quot;John Doe, 30, Engineer&quot; \ndata_row2=&quot;Jane Smith, 25, Doctor&quot; \n\ncsv_content=&quot;${header}\\n${data_row1}\\n${data_row2}&quot; \n\necho -e &quot;$csv_content&quot; &gt; data.csv<\/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;\">All the strings are declared in variables. In<code class=\"\" data-line=\"\">csv_content=&quot;${header}\\n${data_row1}\\n${data_row2}&quot;<\/code>, all the variables are separated with newline characters. The concatenated string is stored in<code class=\"\" data-line=\"\">csv_content<\/code>. In the<strong> echo command<\/strong>, the<code class=\"\" data-line=\"\">-e<\/code>option has been used to interpret the backslash escapes. The redirection operator (<strong>&gt;<\/strong>) has redirected the content to the CSV file.<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-33207 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/15.-csv.png\" alt=\"Creating a csv file using concatenation\" width=\"608\" height=\"306\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/15.-csv.png 608w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/15.-csv-300x151.png 300w\" sizes=\"(max-width: 608px) 100vw, 608px\" \/><\/p>\n<p style=\"text-align: justify;\">Executing the bash script, use the<a href=\"https:\/\/linuxsimply.com\/ls-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong> ls command<\/strong><\/a> to see the new CSV file. Below you can see the content of the newly created string:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-33208 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/16.-newcsv.png\" alt=\"Showing the csv file which has columns and rows\" width=\"298\" height=\"88\" \/><\/p>\n<p>The output shows a CSV file that includes <strong>3 columns<\/strong> and <strong>3 rows<\/strong> with the variable name.<\/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;\">The article shows different methods to concatenate strings. In all of these methods placing strings side by side or in a specific position with command substitution and parameter expansion increases the flexibility and versatility of the practical use of string concatenation. The other methods also give flexibility like placing strings next to each other. I hope the users will benefit by gathering the ideas of string concatenation from this article.<\/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=\"Can_I_create_log_files_using_string_concatenation\"><\/span>Can I create log files using string concatenation?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Yes, you can create log files using concatenation. Use the following code to create log files:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Concatenating date to create log file names\n\nlog_prefix=&quot;app_log&quot;\ndate_extension=$(date +&quot;%Y%m%d&quot;)\nlog_file_name=&quot;${log_prefix}_${date_extension}.log&quot;\n\necho &quot;Log File Name: $log_file_name&quot;<\/code><\/pre>\n<p style=\"text-align: justify;\">With the <code class=\"\" data-line=\"\">.log<\/code> extension, a log file name has been created. In the log file name, the underscore (<code class=\"\" data-line=\"\">_<\/code>) is also appended in the string.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_concatenate_two_arrays_into_a_single_array\"><\/span>How to concatenate two arrays into a single array?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To concatenate two arrays, first declare the two arrays which contain 3 elements. Then concatenate the arrays using variable substitution. Here is how:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Declare two arrays\narray1=(&quot;apple&quot; &quot;banana&quot; &quot;cherry&quot;)\narray2=(&quot;orange&quot; &quot;grape&quot; &quot;kiwi&quot;)\n\n# Concatenate arrays\nconcatenated_array=(&quot;${array1[@]}&quot; &quot;${array2[@]}&quot;)\n\n# Print the concatenated array elements\necho &quot;Concatenated Array: ${concatenated_array[@]}&quot;<\/code><\/pre>\n<p>To print the concatenated array, you can use the echo command.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_concatenate_string_to_comma-separated_element\"><\/span>How to concatenate string to comma-separated element?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To concatenate a specific string into a comma-separated string, use the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\n# Comma-separated string\ncomma_separated=&quot;apple,banana,cherry&quot;\n\n# String to concatenate\nsuffix=&quot;_fruit&quot;\n\n# Convert comma-separated string to an array\nIFS=&#039;,&#039; read -ra elements &lt;&lt;&lt; &quot;$comma_separated&quot;\n\n# Concatenate the string to each element\nfor ((i=0; i&lt;${#elements[@]}; i++)); do\nelements[$i]=&quot;${elements[$i]}$suffix&quot;\ndone\n\n# Reconstruct the comma-separated string\nconcatenated_string=$(IFS=, ; echo &quot;${elements[*]}&quot;)\n\n# Print the result\necho &quot;Concatenated String: $concatenated_string&quot;<\/code><\/pre>\n<p style=\"text-align: justify;\">In the code, the comma-separated string has been split using the <strong>Internal Field Separator<\/strong> into elements. The for loop iterates over each element and appends the suffix with each element.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_insert_characters_in_a_string_in_bash\"><\/span>How to insert characters in a string in bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To insert characters or strings into a specific position of a string, use the following code:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\noriginal_string=&quot;This is a sample string.&quot;\n\n# Define the position where characters should be inserted\nposition=10\n\n# Insert characters (in this case, &quot;INSERTED &quot;) at the specified position\nmodified_string=&quot;${original_string:0:position}INSERTED ${original_string:position}&quot;\n\necho &quot;Original String: $original_string&quot;\necho &quot;Modified String: $modified_string&quot;<\/code><\/pre>\n<p>Here I have appended a specific string \u201cINSERTED\u201d to the string at the position of <strong>10<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_use_space_underscore_and_newline_characters_in_string_concatenation\"><\/span>Can I use space, underscore, and newline characters in string concatenation?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Yes, you can use space, underscore, and newline characters in string concatenation. Take a look at the code shown below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nstring1=&quot;The first line of the string. &quot;\nstring2=&quot;The second line of the string.&quot;\nstring=&quot;$string1$string2&quot;\n\necho $string<\/code><\/pre>\n<p style=\"text-align: justify;\">In this code within the double quotation, you can use the special characters in between the strings at any specific position of the string.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_concatenate_strings_using_join\"><\/span>Can I concatenate strings using join?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Yes, you can concatenate two file strings with the join command. But in this process, the number of columns of the two files should match otherwise it won\u2019t show the expected result. For the <code class=\"\" data-line=\"\">join<\/code> command, here is how the code looks:<\/p>\n<p><code class=\"\" data-line=\"\">join string1.txt string2.txt<\/code><\/p>\n<p style=\"text-align: justify;\">The join command mainly joins strings from two files based on the common field. If it does not find any command field then it won\u2019t show the expected result.<\/p>\n<p><script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": {\n    \"@type\": \"Question\",\n    \"name\": \"Can I concatenate strings using join?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Yes, you can concatenate two file strings with the join command. But in this process, the number of columns of the two files should match otherwise it won\u2019t show the expected result. For the join command, here is how the code looks:<\/p>\n<p>join string1.txt string2.txt<\/p>\n<p>The join command mainly joins strings from two files based on the common field. If it does not find any command field then it won\u2019t show the expected result.\"\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\/operations\/string-length\/\" target=\"_blank\" rel=\"noopener\">How to Find Length of String in Bash [6 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 Operations&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\/operations\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/\" target=\"_blank\" rel=\"noopener\">Bash String Operations<\/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;33173&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;String Concatenation in Bash [6 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>Concatenation means to join two or more elements altogether. When two strings are concatenated in a bash string, it generally &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"String Concatenation in Bash [6 Methods]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#more-33173\" aria-label=\"Read more about String Concatenation in Bash [6 Methods]\">Read more<\/a><\/p>\n","protected":false},"author":314907,"featured_media":33214,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[191],"class_list":["post-33173","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-string-operations","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>String Concatenation in Bash [6 Methods] - LinuxSimply<\/title>\n<meta name=\"description\" content=\"Explore the article to learn the methods of bash string concatenation and enhance the script flexibility and functionality efficiently.\" \/>\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\/operations\/concatenation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"String Concatenation in Bash [6 Methods] - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"Explore the article to learn the methods of bash string concatenation and enhance the script flexibility and functionality efficiently.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/\" \/>\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-01-02T09:33:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-11T06:31:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/Bash-String-Concatenation.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\\\/operations\\\/concatenation\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/operations\\\/concatenation\\\/\"},\"author\":{\"name\":\"Afia Zahin Oishi\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/2afb5d809ba746cd33b77eb2639949d7\"},\"headline\":\"String Concatenation in Bash [6 Methods]\",\"datePublished\":\"2024-01-02T09:33:55+00:00\",\"dateModified\":\"2024-02-11T06:31:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/operations\\\/concatenation\\\/\"},\"wordCount\":2183,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/operations\\\/concatenation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Bash-String-Concatenation.png\",\"keywords\":[\"string operations\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/operations\\\/concatenation\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/operations\\\/concatenation\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/operations\\\/concatenation\\\/\",\"name\":\"String Concatenation in Bash [6 Methods] - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/operations\\\/concatenation\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/operations\\\/concatenation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Bash-String-Concatenation.png\",\"datePublished\":\"2024-01-02T09:33:55+00:00\",\"dateModified\":\"2024-02-11T06:31:11+00:00\",\"description\":\"Explore the article to learn the methods of bash string concatenation and enhance the script flexibility and functionality efficiently.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/operations\\\/concatenation\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/operations\\\/concatenation\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/operations\\\/concatenation\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Bash-String-Concatenation.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Bash-String-Concatenation.png\",\"width\":400,\"height\":400,\"caption\":\"A overview on bash string concatenation\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/operations\\\/concatenation\\\/#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\":\"Bash String Operations\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/string\\\/operations\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"String Concatenation in Bash [6 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":"String Concatenation in Bash [6 Methods] - LinuxSimply","description":"Explore the article to learn the methods of bash string concatenation and enhance the script flexibility and functionality efficiently.","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\/operations\/concatenation\/","og_locale":"en_US","og_type":"article","og_title":"String Concatenation in Bash [6 Methods] - LinuxSimply","og_description":"Explore the article to learn the methods of bash string concatenation and enhance the script flexibility and functionality efficiently.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/afia.zahin.7796?mibextid=ZbWKwL","article_published_time":"2024-01-02T09:33:55+00:00","article_modified_time":"2024-02-11T06:31:11+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/Bash-String-Concatenation.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\/operations\/concatenation\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/"},"author":{"name":"Afia Zahin Oishi","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/2afb5d809ba746cd33b77eb2639949d7"},"headline":"String Concatenation in Bash [6 Methods]","datePublished":"2024-01-02T09:33:55+00:00","dateModified":"2024-02-11T06:31:11+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/"},"wordCount":2183,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/Bash-String-Concatenation.png","keywords":["string operations"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/","name":"String Concatenation in Bash [6 Methods] - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/Bash-String-Concatenation.png","datePublished":"2024-01-02T09:33:55+00:00","dateModified":"2024-02-11T06:31:11+00:00","description":"Explore the article to learn the methods of bash string concatenation and enhance the script flexibility and functionality efficiently.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/Bash-String-Concatenation.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/01\/Bash-String-Concatenation.png","width":400,"height":400,"caption":"A overview on bash string concatenation"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/concatenation\/#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":"Bash String Operations","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/string\/operations\/"},{"@type":"ListItem","position":5,"name":"String Concatenation in Bash [6 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\/33173","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=33173"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/33173\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/33214"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=33173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=33173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=33173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}