What is the purpose of the "+=" operator in Bash?

QuestionsQuestions8 SkillsProShell ArraysSep, 29 2025
091

The += operator in Bash is used for string concatenation and for adding values to variables. When used with strings, it appends the right-hand operand to the variable on the left. When used with numbers, it adds the right-hand operand to the variable on the left.

Example of String Concatenation:

string="Hello"
string+=" World"
echo $string  # Output: Hello World

Example of Numeric Addition:

number=5
number+=3
echo $number  # Output: 8

In both cases, the += operator modifies the variable by adding or appending the specified value.

0 Comments

no data
Be the first to share your comment!