{"id":67132,"date":"2022-10-27T08:48:09","date_gmt":"2022-10-27T08:48:09","guid":{"rendered":"\/tutorials\/?p=67132"},"modified":"2026-03-10T10:11:39","modified_gmt":"2026-03-10T10:11:39","slug":"bash-concatenate-strings","status":"publish","type":"post","link":"\/uk\/tutorials\/bash-concatenate-strings\/","title":{"rendered":"How to concatenate strings in bash: A guide for connecting string variables"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>The majority of programming languages can connect two or more strings. One programming language that makes it effortless to concatenate variables is <strong>bash<\/strong>.<\/p><p>What makes bash special is that string variables can be connected without the use of dedicated commands or functions. In other words, to combine string data, users can use simple variable manipulation or apply the same logic with the <strong>addition assignment operator (+=)<\/strong>.<\/p><p>In this tutorial, we will explain bash scripting, go over what bash concatenate strings are, and provide a variety of ways to concatenate strings.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-69262\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet.png 2048w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet-300x83.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet-1536x425.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet-150x41.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet-768x212.png 768w\" sizes=\"(max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure>\n<\/div><p>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-what-is-bash-scripting\">What Is Bash Scripting?<\/h2><p>Bash shell scripting allows users to execute hundreds of <a href=\"\/uk\/tutorials\/linux-commands\/\">Linux commands<\/a> with a single script instead of writing them all down one by one. It is extra helpful for users looking to automate operations on their physical server or <a href=\"\/uk\/vps-hosting\">VPS hosting<\/a> environment, enhancing productivity.<\/p><p>For example, any command a user can run natively on a terminal can be put into a bash script. This also applies to functions, so instead of writing them down every time, users only need to write a function once and reuse it in any bash scripts.<\/p><p>Any script starts with a <a href=\"\/uk\/tutorials\/how-to-run-sh-file-in-linux\/\"><strong>.sh<\/strong> file<\/a> and contains a similar structure:<\/p><pre class=\"wp-block-preformatted\">#!\/bin\/bash\n# Creates a new variable \"Hello, World\"\nmybashvariable=\"Hello, World\"\necho $mybashvariable<\/pre><p>The first line tells the terminal to run the script using bash exclusively, and all the following lines are the actual script itself.<\/p><p>In this particular example, the script created a new variable named <strong>mybashvariable<\/strong> and gave it a &ldquo;<strong>Hello, World<\/strong>&rdquo; value, and the script will print the value out.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"\/uk\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/10\/Bash-script-to-join-two-strings.png\"><img decoding=\"async\" width=\"580\" height=\"110\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/10\/Bash-script-to-join-two-strings.png\/public\" alt=\"Bash script to join two strings\" class=\"wp-image-67134\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-script-to-join-two-strings.png 580w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-script-to-join-two-strings-300x57.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-script-to-join-two-strings-150x28.png 150w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/a><\/figure><\/div><p><div class=\"protip\"><div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                   What Is Concatenation in Linux?\n                <\/p>\n            <\/div>\n            <p class=\"protip__content\"> Concatenation operation in bash is the process of attaching a string to the end of another string. Bash allows its users to concatenate strings by writing strings one after the other or joining them using the += operator. <\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-string-concatenation-adding-one-string-variable-after-the-other\">String Concatenation &ndash; Adding One String Variable After the Other<\/h2><p>The simplest string concatenation method is adding one string variable after the other. The following sections will show three different ways to do just that.<\/p><h3 class=\"wp-block-heading\" id=\"h-string-concatenation-using-literal-strings\">String Concatenation Using Literal Strings<\/h3><p>Literal strings are printed literally, and there are two ways to print out a string literal &ndash; using singular quotes or a backlash symbol with regular double quotes. For example, we will create a new literal string variable without quotes and echo it:<\/p><pre class=\"wp-block-preformatted\">#!\/bin\/bash\nvariablename=usrbinenv\necho \"$variablename\"<\/pre><p>In this case, the result would be:<\/p><pre class=\"wp-block-preformatted\"># Result\nusrbinenv<\/pre><p>Now, when we add <strong>singular<\/strong> or <strong>double quotes<\/strong> to the string variable name, the echo command will print the value literally:<\/p><pre class=\"wp-block-preformatted\">#!\/bin\/bash\nvariablename='usrbinenv'\necho \"$variablename\"<\/pre><p>Here&rsquo;s the result:<\/p><pre class=\"wp-block-preformatted\"># Result\nusrbinenv<\/pre><p>Next, we will apply this logic to concatenate two strings:<\/p><pre class=\"wp-block-preformatted\">#!\/bin\/bash\nvariablename='usrbinenv'\necho \"$variablename Bash_Is_Awesome\"<\/pre><p>We can also cover the last line&rsquo;s variable using <strong>rounded brackets<\/strong> in order to guard it. Curly brackets are helpful if you got a variety of variables:<\/p><pre class=\"wp-block-preformatted\">echo \"${variablename} Bash_Is_Awesome\"<\/pre><p>In both cases, the result will be shown as:<\/p><pre class=\"wp-block-preformatted\">usrbinenv Bash_Is_Awesome<\/pre><h3 class=\"wp-block-heading\" id=\"h-string-concatenation-of-multiple-variables\">String Concatenation of Multiple Variables<\/h3><p>Multiple string variables can be easily joined together with clear-cut variable manipulation.<\/p><p>For example, in the following bash script, we will use three different variables to create combined values. The echo command will subsequently print out the string data:<\/p><pre class=\"wp-block-preformatted\">#!\/bin\/bash\nvariablename='usrbinenv '\nmyvariable='_Awesome'\nanothervariable=\"$variablename\"Bash_Is\"$myvariable\"\necho \"$anothervariable\"<\/pre><p>Here&rsquo;s what the result will look like:<\/p><pre class=\"wp-block-preformatted\">usrbinenv Bash_Is_Awesome<\/pre><h3 class=\"wp-block-heading\" id=\"h-string-concatenation-of-numbers-and-strings\">String Concatenation of Numbers and Strings<\/h3><p>Bash allows its users to concatenate one or more variables that are not string-type. For this reason, it is possible to concatenate multiple variables, which can be strings or numbers:<\/p><pre class=\"wp-block-preformatted\">#!\/bin\/bash\nfirstvariable=\" Hello, World \"\nsecondvariable=\"Hello, Hostinger \"\nthirdvariable=\" I now know how to concatenate strings in bash.\"\nfourthvariable=\"$secondvariable\"and\"$firstvariable\"means\"$thirdvariable\"\necho $fourthvariable<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/uk\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/10\/Bash-string-concatenation-of-numbers-and-strings.png\"><img decoding=\"async\" width=\"1024\" height=\"92\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/10\/Bash-string-concatenation-of-numbers-and-strings.png\/w=1024,h=1024,fit=scale-down\" alt=\"Bash string concatenation of numbers and strings\" class=\"wp-image-67140\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-string-concatenation-of-numbers-and-strings.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-string-concatenation-of-numbers-and-strings-300x27.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-string-concatenation-of-numbers-and-strings-150x14.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-string-concatenation-of-numbers-and-strings-768x69.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-string-concatenation-using-the-operator\">String Concatenation Using the += Operator<\/h2><p>Another way to join two or more strings to make a concatenated string is to use the addition assignment operator (+=). This operator makes it possible to connect strings using one or more variables.<\/p><p>For example, the following script can be used to join two strings with the use of a single variable:<\/p><pre class=\"wp-block-preformatted\">#!\/bin\/bash\nmystring=\"I would like to generate a meaningful output, please. \"\nmystring+=\"Not a chance, friend!\"\necho \"$mystring\"<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/uk\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/10\/Connecting-both-strings-without-any-built-in-function-or-command-in-bash.-Combined-values-are-achieved-using-the-append-operator.png\"><img decoding=\"async\" width=\"1024\" height=\"105\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/10\/Connecting-both-strings-without-any-built-in-function-or-command-in-bash.-Combined-values-are-achieved-using-the-append-operator.png\/w=1024,h=1024,fit=scale-down\" alt=\"Connecting both strings without any built-in function or command in bash. Combined values are achieved using the append += operator\" class=\"wp-image-67142\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Connecting-both-strings-without-any-built-in-function-or-command-in-bash.-Combined-values-are-achieved-using-the-append-operator.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Connecting-both-strings-without-any-built-in-function-or-command-in-bash.-Combined-values-are-achieved-using-the-append-operator-300x31.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Connecting-both-strings-without-any-built-in-function-or-command-in-bash.-Combined-values-are-achieved-using-the-append-operator-150x15.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Connecting-both-strings-without-any-built-in-function-or-command-in-bash.-Combined-values-are-achieved-using-the-append-operator-768x79.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>A similar result can be achieved using two variables:<\/p><pre class=\"wp-block-preformatted\">#!\/bin\/bash\nfirststring=\"This is a single string. \"\nsecondstring=\"Which makes this a resulting string.\"\n# Curly brackets between $secondvariable are called variable interpolation.\nfirststring+=\"${secondstring}\"\necho $firststring<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"\/uk\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/10\/Bash-append-string-operator-use-case-example.-Two-strings-are-taken-and-concatenated-string-is-made-with-the-help-of-the-append-operator.png\"><img decoding=\"async\" width=\"880\" height=\"110\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/10\/Bash-append-string-operator-use-case-example.-Two-strings-are-taken-and-concatenated-string-is-made-with-the-help-of-the-append-operator.png\/public\" alt=\"Bash append string operator use-case example. Two strings are taken and concatenated string is made with the help of the append operator\" class=\"wp-image-67144\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-append-string-operator-use-case-example.-Two-strings-are-taken-and-concatenated-string-is-made-with-the-help-of-the-append-operator.png 880w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-append-string-operator-use-case-example.-Two-strings-are-taken-and-concatenated-string-is-made-with-the-help-of-the-append-operator-300x38.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-append-string-operator-use-case-example.-Two-strings-are-taken-and-concatenated-string-is-made-with-the-help-of-the-append-operator-150x19.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-append-string-operator-use-case-example.-Two-strings-are-taken-and-concatenated-string-is-made-with-the-help-of-the-append-operator-768x96.png 768w\" sizes=\"(max-width: 880px) 100vw, 880px\" \/><\/a><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-concatenating-numeric-strings\">Concatenating Numeric Strings<\/h3><p>The append operator method can also be used exclusively to append numeric string variables.<\/p><pre class=\"wp-block-preformatted\">#!\/bin\/bash\nnumeric_string=2050\nnumeric_string+=0502\necho $numeric_string<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"\/uk\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/10\/Bash-script-to-join-numeric-string-variables.-Plus-and-equal-sign-correspond-to-append-operator.png\"><img decoding=\"async\" width=\"640\" height=\"110\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/10\/Bash-script-to-join-numeric-string-variables.-Plus-and-equal-sign-correspond-to-append-operator.png\/public\" alt=\"Bash script to join numeric string variables. Plus and equal sign correspond to append operator\" class=\"wp-image-67145\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-script-to-join-numeric-string-variables.-Plus-and-equal-sign-correspond-to-append-operator.png 640w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-script-to-join-numeric-string-variables.-Plus-and-equal-sign-correspond-to-append-operator-300x52.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-script-to-join-numeric-string-variables.-Plus-and-equal-sign-correspond-to-append-operator-150x26.png 150w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/figure><\/div><p>However, if you would like to add the numbers together, this logic needs to be used:<\/p><pre class=\"wp-block-preformatted\">#!\/bin\/bash\nx=3\ny=5\nz=6\n((x+=y+=z))\necho $x<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"\/uk\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/10\/Bash-script-to-add-three-numbers-together.png\"><img decoding=\"async\" width=\"640\" height=\"110\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/10\/Bash-script-to-add-three-numbers-together.png\/public\" alt=\"Bash script to add three numbers together\" class=\"wp-image-67147\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-script-to-add-three-numbers-together.png 640w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-script-to-add-three-numbers-together-300x52.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-script-to-add-three-numbers-together-150x26.png 150w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-concatenating-strings-using-bash-for-loop\">Concatenating Strings Using Bash for Loop<\/h3><p>A more advanced way of using the bash concatenate functionality is implementing it into the <a href=\"\/uk\/tutorials\/bash-for-loop-guide-and-examples\/\">bash for loop<\/a>.<\/p><p>In the following example, we got a <strong>myvariable<\/strong> with three strings and a variable named <strong>results<\/strong> with an empty string. With the help of the <strong>bash for<\/strong> <strong>loop<\/strong>, we will be able to combine strings from <strong>myvariable<\/strong> with our string:<\/p><pre class=\"wp-block-preformatted\">#!\/bin\/bash\nmyvariable=\"bash concatenation Hostinger\"\nresults=\"\"\nfor i in $myvariable\ndo\nresults+=\"The answer is $i... \"\ndone\necho $results<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/uk\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/10\/Bash-for-loop-example-in-a-bash-script.-It-is-used-to-join-three-strings-with-the-preferred-string.-Echo-command-prints-out-the-combined-result.png\"><img decoding=\"async\" width=\"1024\" height=\"99\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/10\/Bash-for-loop-example-in-a-bash-script.-It-is-used-to-join-three-strings-with-the-preferred-string.-Echo-command-prints-out-the-combined-result.png\/w=1024,h=1024,fit=scale-down\" alt=\"Bash for loop example in a bash script. It is used to join three strings with the preferred string. Echo command prints out the combined result\" class=\"wp-image-67148\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-for-loop-example-in-a-bash-script.-It-is-used-to-join-three-strings-with-the-preferred-string.-Echo-command-prints-out-the-combined-result.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-for-loop-example-in-a-bash-script.-It-is-used-to-join-three-strings-with-the-preferred-string.-Echo-command-prints-out-the-combined-result-300x29.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-for-loop-example-in-a-bash-script.-It-is-used-to-join-three-strings-with-the-preferred-string.-Echo-command-prints-out-the-combined-result-150x14.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/10\/Bash-for-loop-example-in-a-bash-script.-It-is-used-to-join-three-strings-with-the-preferred-string.-Echo-command-prints-out-the-combined-result-768x74.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>The bash programming language is a convenient and efficient tool for various variable manipulation actions. One of the most important examples is the ability to join different string variables into one.<\/p><p>In this tutorial, we&rsquo;ve gone through the definition of bash scripting and concatenation. We also learned how to join string variables with two different methods.<\/p><p>We hope you found this tutorial useful. If you have any further questions, feel free to leave them in the comments section below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The majority of programming languages can connect two or more strings. One programming language that makes it effortless to concatenate variables is bash. What makes bash special is that string variables can be connected without the use of dedicated commands or functions. In other words, to combine string data, users can use simple variable manipulation [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/uk\/tutorials\/bash-concatenate-strings\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":279,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Bash Concatenate Strings: Joining Variables in Linux","rank_math_description":"How to bash concatenate strings? A guide on concatenation also known as connecting variables is an action commonly used in string operations.","rank_math_focus_keyword":"bash concatenate strings","footnotes":""},"categories":[22640],"tags":[],"class_list":["post-67132","post","type-post","status-publish","format-standard","hentry","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/bash-concatenate-strings","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/como-concatenar-strings-no-bash","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/concatener-des-chaines-en-bash","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/como-concatenar-cadenas-en-bash","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-menggabungkan-string-di-bash","default":0},{"locale":"en-GB","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/bash-concatenate-strings","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/bash-concatenate-strings","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/bash-concatenate-strings","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/como-concatenar-cadenas-en-bash","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/como-concatenar-cadenas-en-bash","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/como-concatenar-cadenas-en-bash","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/bash-concatenate-strings","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/bash-concatenate-strings","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/como-concatenar-strings-no-bash","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/bash-concatenate-strings","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/bash-concatenate-strings","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/67132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/users\/279"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/comments?post=67132"}],"version-history":[{"count":8,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/67132\/revisions"}],"predecessor-version":[{"id":128814,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/67132\/revisions\/128814"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/media?parent=67132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/categories?post=67132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/tags?post=67132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}