Bash += and -=: Difference between revisions
Jump to navigation
Jump to search
Line 9: | Line 9: | ||
+= 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: | += 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: | ||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
i=0 | |||
((i+=1)) | |||
echo ${i} | |||
</syntaxhighlight> | |||
displays: | |||
<syntaxhighlight lang='bash'> | |||
1 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
The += can be used on string values as such: | The += can be used on string values as such: | ||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 05:33, 8 May 2020
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
The += can be used on string values as such: