{"id":30531,"date":"2026-04-23T17:08:58","date_gmt":"2026-04-23T15:08:58","guid":{"rendered":"https:\/\/contabo.com\/blog\/?p=30531"},"modified":"2026-05-12T10:04:58","modified_gmt":"2026-05-12T08:04:58","slug":"how-to-concatenate-strings-in-bash-guide-with-code-examples","status":"publish","type":"post","link":"https:\/\/contabo.com\/blog\/how-to-concatenate-strings-in-bash-guide-with-code-examples\/","title":{"rendered":"How to Concatenate Strings in Bash: Guide with Code Examples\u00a0"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/05\/blog-head_how2-bash-concatenate-strings.webp\" alt=\"How to Concatenate Strings in Bash: Guide with Code Examples\u00a0\" class=\"wp-image-30538\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/05\/blog-head_how2-bash-concatenate-strings.webp 1200w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/05\/blog-head_how2-bash-concatenate-strings-600x315.webp 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/05\/blog-head_how2-bash-concatenate-strings-768x403.webp 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p><strong>What you need to know:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Bash concatenate strings operations are simple: put two variables or literals next to each other and they join.<\/li>\n\n\n\n<li>Use the += append operator when you are building a string across several steps.<\/li>\n\n\n\n<li>printf gives you clean formatting when you want control over spacing and newlines.<\/li>\n\n\n\n<li>Heredoc handles multiline strings without painful escaping.<\/li>\n\n\n\n<li>Most bugs come from quoting, spaces, or unset variables, not the concatenation itself.<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/li>\n<\/ul>\n\n\n\n<p>Joining strings in bash looks odd the first time you see it. There is no + operator. You just stick variables side by side and it works. This guide walks through the main ways to bash concatenate strings, shows common problems, and covers when each method is the right pick.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-bash-scripting\">What Is Bash Scripting<\/h2>\n\n\n\n<p>Bash scripting is writing small programs in the Bash shell. It is one of the most common forms of shell scripting on Linux and is used for automation, server management, deployment, and glue code between tools. Bash scripts are plain text files that the shell reads from top to bottom, running each line as a command.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<p>Most Linux servers have Bash installed by default, which is why shell scripting in Bash is often the fastest way to get something done. You write a .sh file, mark it executable, and run it. No compiler. No build step. That makes it a natural choice for tasks where string handling is one piece of a larger job.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"when-to-use-bash-for-string-operations\">When to Use Bash for String Operations<\/h2>\n\n\n\n<p>Reach for bash scripting when the strings are small, the logic is simple, and the script needs to run with only the tools already on the system. Bash variables and string operations are fast enough for config generation, log parsing, filename building, and short automation tasks.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<p>If you are doing heavy text processing, a different language is usually cleaner. But for joining a few bash variables into a path or a message, bash is hard to beat.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-string-concatenation-in-linux\">What Is String Concatenation in Linux<\/h2>\n\n\n\n<p>So what is string concatenation? It is the act of joining two or more strings into one. In Bash, a bash string is just a sequence of characters stored in a variable or written as a literal. You concatenate them by placing them next to each other, with no operator between.<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>first=\"hello\"<br>second=\"world\"<br>full=\"$first $second\"<br>echo \"$full\"   <em># hello world<\/em><\/code><\/pre>\n\n\n\n<p>That is the core idea behind almost every method shown below.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"method-1-variable-juxtaposition\">Method 1: Variable Juxtaposition<\/h2>\n\n\n\n<p>The simplest way to bash concatenate strings is juxtaposition: put the bash variables next to each other inside a new variable or a quoted string.<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>name=\"Ada\"<br>greeting=\"Hello, $name!\"<br>echo \"$greeting\"   <em># Hello, Ada!<\/em><\/code><\/pre>\n\n\n\n<p>No operator. No function. Just order and quoting.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"concatenating-literal-strings\">Concatenating Literal Strings<\/h3>\n\n\n\n<p>You can bash concatenate strings made up of literals the same way, by writing them inside one pair of quotes or by placing two quoted bash string fragments side by side.<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>path=\"\/var\"\"\/log\"   # \/var\/log<br>message=\"user: \"\"$USER\"<\/code><\/pre>\n\n\n\n<p>The second form is useful when you want to keep parts of the string visually separate while still joining them.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"using-curly-braces-for-variable-guarding\">Using Curly Braces for Variable Guarding<\/h3>\n\n\n\n<p>When a bash variable sits next to text that looks like part of its name, wrap it in <code>${}<\/code>. This protects the bash string from being parsed wrong.<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>file=\"report\"<br>name=\"${file}_2026.txt\"   <em># report_2026.txt<\/em><\/code><\/pre>\n\n\n\n<p>Without the braces, <code>$file_2026<\/code> would look like a new variable. Curly braces are the cheapest fix for one of the most common bash bugs.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"method-2-the--append-operator\">Method 2: The += Append Operator<\/h2>\n\n\n\n<p>The <code>+=<\/code> operator is a bash append string shortcut. It grows a variable in place, which is useful when you want to add to a string without rewriting it. String concatenation bash style with <code>+=<\/code> reads cleanly and runs fast.<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>log=\"Started\"<br>log+=\" at $(date)\"<br>echo \"$log\"<br><em># Output: Started at Mon May 11 17:20:00 CEST 2026<\/em><\/code><\/pre>\n\n\n\n<p>Each <code>+=<\/code> appends to the existing value. No need to retype the variable name on the right-hand side, and no risk of forgetting a dollar sign in the middle of a long string.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"building-strings-incrementally-in-loops\">Building Strings Incrementally in Loops<\/h3>\n\n\n\n<p><code>+=<\/code> shines inside loops. It also works for bash arrays, which is handy when you want to collect items and turn them into one string at the end. String concatenation bash patterns inside loops look like this:<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>result=\"\"<br>for item in one two three; do<br>result+=\"$item,\"<br>done<br>echo \"${result%,}\"   <em># one,two,three<\/em><\/code><\/pre>\n\n\n\n<p>For list-like data, using bash arrays and then joining with IFS (the Internal Field Separator, the variable Bash uses to decide how to split and join fields) is often cleaner than building a string hop by hop.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>parts=(one two three)<br>IFS=','; joined=\"${parts[*]}\"; unset IFS<br>echo \"$joined\"   <em># one,two,three<\/em><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"method-3-concatenating-with-printf\">Method 3: Concatenating with printf<\/h2>\n\n\n\n<p>printf is useful when you want exact control over formatting. It is stricter than echo, which is why many scripts use it for anything printed to logs or passed to another tool. For bash concatenate strings tasks, bash printf also works as a clean joiner.<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>first=\"api\"<br>second=\"contabo\"<br>third=\"com\"<br>url=$(printf \"%s.%s.%s\" \"$first\" \"$second\" \"$third\")<br>echo \"$url\"   <em># api.contabo.com<\/em><\/code><\/pre>\n\n\n\n<p>The format string defines the shape, and each <code>%s<\/code> picks up one argument. No quoting surprises, no spacing mistakes.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"method-4-using-here-strings-and-heredoc\">Method 4: Using Here-Strings and Heredoc<\/h2>\n\n\n\n<p>When the string has more than one line, quoting gets painful fast. Bash heredoc solves that. A heredoc lets you write a bash multiline string between two markers and assign it to a variable without escaping every quote. Reach for it when you would otherwise need several <code>+=<\/code> lines or stacked echoes, for example a config file body, an email template, or a multi-line log message.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>message=$(cat &lt;&lt;EOF<br>Hello, $USER.<br>Your server is ready.<br>EOF<br>)<br>echo \"$message\"<br><em># Output:<\/em><br><em># Hello, yourname.<\/em><br><em># Your server is ready.<\/em><\/code><\/pre>\n\n\n\n<p>Variables expand inside the block. If you want the raw text with no expansion, quote the opening marker like <code>&lt;&lt;'EOF'<\/code>. That is the difference between a template that fills in values and a literal block that prints exactly what you typed.<\/p>\n\n\n\n<p>Here is the same pattern with no expansion, useful when you\u2019re writing out something like a config snippet that contains literal dollar signs:<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/images\/110844766\/f59ed230-f995-4696-85d2-b06086075861\/image.jpg\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>config=$(cat &lt;&lt;'EOF'<br>host=$SERVER_HOST<br>port=$SERVER_PORT<br>EOF<br>)<br>echo \"$config\"<br><em># Output:<\/em><br><em># host=$SERVER_HOST<\/em><br><em># port=$SERVER_PORT<\/em><\/code><\/pre>\n\n\n\n<p>Here-strings are the smaller sibling. They feed a single bash string to a command:<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>grep \"error\" &lt;&lt;&lt; \"$log\"<\/code><\/pre>\n\n\n\n<p>Both patterns keep bash multiline string handling readable.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"bash-string-manipulation-techniques\">Bash String Manipulation Techniques<\/h2>\n\n\n\n<p>Concatenation is one part of bash string manipulation. Once you have the string, Bash gives you operators for slicing, replacing, and checking length. Combined with bash echo or printf, you can shape almost any output without calling external tools.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"substring-extraction-and-replacement\">Substring Extraction and Replacement<\/h3>\n\n\n\n<p>Bash string manipulation uses <code>${var:offset:length}<\/code> for substrings and <code>${var\/old\/new}<\/code> for replacement. These work directly on bash variables without needing sed or awk.<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>text=\"hello world\"<br>echo \"${text:0:5}\"          <em># hello<\/em><br>echo \"${text\/world\/bash}\"   <em># hello bash<\/em><\/code><\/pre>\n\n\n\n<p>Short, fast, and built in.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"appending-to-multiline-strings\">Appending to Multiline Strings<\/h3>\n\n\n\n<p>You can extend a bash multiline string by appending more lines with <code>+=<\/code> and a leading newline, or by writing a second bash heredoc and joining the two.<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>block=$(cat &lt;&lt;EOF<br>Line 1<br>Line 2<br>EOF<br>)<br>block+=$'\\nLine 3'<br>echo \"$block\"<\/code><\/pre>\n\n\n\n<p>The <code>$'\\n'<\/code> syntax inserts an actual newline, which is safer than trying to embed one inside double quotes.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"common-bash-string-errors-and-fixes\">Common Bash String Errors and Fixes<\/h2>\n\n\n\n<p>Most bash scripting string bugs fall into a short list of patterns. Watch for these and you will avoid most of the common bash errors.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Forgetting to quote a variable with spaces: <code>cp $file \/tmp<\/code> breaks if <code>$file<\/code> contains spaces. Use <code>cp \"$file\" \/tmp<\/code>.<\/li>\n\n\n\n<li>Missing curly braces next to text: <code>\"$name_log\"<\/code> looks for a variable called <code>name_log<\/code>. Write <code>\"${name}_log\"<\/code>.<\/li>\n\n\n\n<li>Using single quotes when you need expansion: <code>'Hello $name'<\/code> prints literally. Use double quotes to interpolate.<\/li>\n\n\n\n<li>Empty variables producing empty strings silently: use <code>set -u<\/code> to catch unset variables early.<\/li>\n\n\n\n<li>Mixing arrays and strings without care: <code>${arr[*]}<\/code> and <code>${arr[@]}<\/code> behave differently inside quotes.<\/li>\n<\/ul>\n\n\n\n<p>Most of these look like small stylistic things. They are not. They are where real scripts break.<a rel=\"noreferrer noopener nofollow\" target=\"_blank\" href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faq-bash-string-concatenation\">FAQ: Bash String Concatenation<\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1778513280738\"><strong class=\"schema-faq-question\">How do I concatenate strings in bash?<\/strong> <p class=\"schema-faq-answer\">The simplest way to bash concatenate strings is to place variables and literals next to each other inside double quotes, for example <code>full=\"$first $second\"<\/code>. That works for most cases without any extra operators.<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1778513290316\"><strong class=\"schema-faq-question\">How do I append to a string variable in bash?<\/strong> <p class=\"schema-faq-answer\">Use the <code>+=<\/code> operator, which is the standard bash append string approach. String concatenation bash style looks like <code>log+=\" more text\"<\/code>, and it grows the existing variable in place without rewriting it.<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1778513390013\"><strong class=\"schema-faq-question\">What does += do in bash scripting?<\/strong> <p class=\"schema-faq-answer\">In bash scripting, <code>+=<\/code> appends the right-hand value to the existing bash variables on the left. For strings, it adds the new text to the end. For integers declared with <code>declare -i<\/code>, it performs addition instead.<a href=\"https:\/\/ppl-ai-file-upload.s3.amazonaws.com\/web\/direct-files\/attachments\/110844766\/6e452b23-de7c-42ba-9154-5b847c730fb2\/How-to-Concatenate-Strings-in-Bash-Guide-with-Code-Examples.docx\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1778513394632\"><strong class=\"schema-faq-question\">How do I join strings across multiple lines in bash?<\/strong> <p class=\"schema-faq-answer\">Use a bash heredoc to build a bash multiline string in one block, then assign it to a variable with <code>$(cat &lt;&lt;EOF ... EOF)<\/code>. Bash heredoc blocks expand variables by default, which makes joining values across many lines easy to read.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>A practical guide to Bash string concatenation, with examples for juxtaposition, the += operator, printf, and heredoc multiline blocks. Includes IFS array joining, common errors, and quick fixes.<\/p>\n","protected":false},"author":63,"featured_media":30538,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18],"tags":[2368,4192,4202,4193,4203,4198,4197,4199,510,4204,4196,4201,4195,4194,4200],"ppma_author":[1492],"class_list":["post-30531","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-automation","tag-bash","tag-bash-arrays","tag-bash-scripting","tag-command-line","tag-here-strings","tag-heredoc","tag-ifs","tag-linux","tag-multiline-strings","tag-printf","tag-quoting","tag-shell-scripting","tag-string-concatenation","tag-variables"],"uagb_featured_image_src":{"full":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/05\/blog-head_how2-bash-concatenate-strings.webp",1200,630,false],"thumbnail":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/05\/blog-head_how2-bash-concatenate-strings-150x150.webp",150,150,true],"medium":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/05\/blog-head_how2-bash-concatenate-strings-600x315.webp",600,315,true],"medium_large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/05\/blog-head_how2-bash-concatenate-strings-768x403.webp",768,403,true],"large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/05\/blog-head_how2-bash-concatenate-strings.webp",1200,630,false],"1536x1536":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/05\/blog-head_how2-bash-concatenate-strings.webp",1200,630,false],"2048x2048":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2026\/05\/blog-head_how2-bash-concatenate-strings.webp",1200,630,false]},"uagb_author_info":{"display_name":"Christopher Carter","author_link":"https:\/\/contabo.com\/blog\/author\/christophercarter\/"},"uagb_comment_info":0,"uagb_excerpt":"A practical guide to Bash string concatenation, with examples for juxtaposition, the += operator, printf, and heredoc multiline blocks. Includes IFS array joining, common errors, and quick fixes.","authors":[{"term_id":1492,"user_id":63,"is_guest":0,"slug":"christophercarter","display_name":"Christopher Carter","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/63db81672a5ce4c1e8ee39753d00251d561b5b3a9967febf1c4f662024cef00f?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/30531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/comments?post=30531"}],"version-history":[{"count":2,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/30531\/revisions"}],"predecessor-version":[{"id":30542,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/30531\/revisions\/30542"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media\/30538"}],"wp:attachment":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media?parent=30531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/categories?post=30531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/tags?post=30531"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=30531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}