Bash Scripting - How to Concatenate Strings

Somewhere around 1989, Brian Fox created Bash as a free software substitute for the Bourne shell for the GNU Project. It is a command processor, usually running in a text window, where the user can write commands that cause actions. Bash can also read and execute commands from shell script files. It supports filename globbing (wildcard matching), piping, here documents, command substitution, variables, and control structures for conditional testing and iteration, as do other Unix shells.

Okay, now let's get straight to the point. Actually, I got question from friend of mine about bash concatenate strings. I believe I don't have to explain where this bash script should be run. Indeed you need linux or unix shell with bash to run this. The rest is actually really simple and easy. Here is my sample code:

As you can see in my example above, there are various ways to concatenate string in bash.

The simplest way as in the EXAMPLE1 is by placing them together side by side and bamm... you have concatenate them.

In EXAMPLE2, I put curly bracket to avoid ambiguity between the variables. And finally in EXAMPLE3, I'm showing you how it is also possible to concatenate strings in Bash using += Operator

I hope now you should have a good understanding of how to concatenate strings in Bash. Feel free to leave your comments if you have other questions. Until then, happy coding!


Comments

Popular posts from this blog

How to Create Hyperlink on Blogger Post

How to Add a Sudo User on AlmaLinux 9.2 (Turquoise Kodkod): A Step-by-Step Guide

How to Check AlmaLinux Version on the Command Line: A Quick Guide