FreeKB - Bash (Scripting) append values to a variable (+=)
Bash (Scripting) - append values to a variable (+=)

Let's say the fruit variable contains the following.

fruit="apple banana orange grape"


The += operator can be used to append values to the end of the variable. In this example, pineapple is appended to the end of the fruit variable.



Printing the fruit variable should now produce the following.

apple banana orange grape pineapple


Add new lines

In this example, a new line is appended to the fruit variable.



Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter c0895 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |