Low Orbit Flux Logo 2 F

Bash Concatenate Strings

Concatenating strings in a BASH is easy. We’re going to show you how to do this. We also have some examples.


c="$a$b"

Here is an example:


#!/bin/bash  
  
a="Apples and Oranges"     # first string
b=" are good."             # second string
  
c="$a$b"                   # concatenate

echo $c                    # new string

The output will look like this:


Apples and Oranges are good.

Here is another example:


#!/bin/bash  

a="apples"
b="oranges"
c="rocks"

echo "I like to eat $a and $b but not $c."

The output will look like this:


I like to eat apples and oranges but not rocks.