Bash += and -=

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

External

Internal

Overview

+= and -= are assignment operators that can be used to increment/decrement the value of the left operand with the value specified after the operator. The operators can be used on integral values as such:

i=0
((i+=1))
echo ${i}

displays:

1

Also:

i=0
((i-=1))
echo ${i}

displays:

-1

+= can be used on string values as such:

s="something"
s+=" else"
echo ${s}

displays:

something else

-= does not work with strings.