Using Bash to Concatenate Strings

Bash scripting makes concatenating strings simple and fun. All the normal Bash features are available and more complex approaches can be applied with looping, splitting text into arrays, and even specifying custom IFS values!

Zack West
alpharithms

--

Image: alpharithms

Bash is a shell programming language designed to provide developers a means to write quick-and-dirty scripts to automate repetitive tasks. It integrates with Linux/Unix tools like grep, cat, and more but also provides language tools like loops and the means to manipulate stings — including string concatenation.

Using bash to concatenate strings is almost eerily simple compared to other full-fledged programming languages like Java, C, or Rust. Where programming languages often require clunky syntax, the use of string formatting models, or even the indexing into arrays — concatenating strings in bash is a very familiar experience. Let’s take a look.

Basic Bash String Concatenation

Bash essentially allows developers to define string variables and then use them together as though they were words in a text. Consider the following bash script:

#!/bin/bash

# define some variables
STRING1="hello"…

--

--

Zack West
alpharithms

Entrepreneur, programmer, designer, and lifelong learner. Can be found taking notes from Mother Nature when not hammering away at the keyboard.