((...)): Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 3: Line 3:
* [[Bash_Concepts#.28.28....29.29|Bash Concepts]]
* [[Bash_Concepts#.28.28....29.29|Bash Concepts]]
* [[Numbers_and_Arithmetic_in_bash|Numbers and Arithmetic in bash]]
* [[Numbers_and_Arithmetic_in_bash|Numbers and Arithmetic in bash]]
 
* [[Bash_%2B%3D_and_-%3D|+= and -=]]
=a=
=b=


=Increment an Integer=
=Increment an Integer=
Line 12: Line 10:
local i=0
local i=0
((i++))
((i++))
</syntaxhighlight>
=Decrement an Integer=
<syntaxhighlight lang='bash'>
local i=1
((i--))
</syntaxhighlight>
=Organizatorium=
Display the value of the variable, then increment it:
<syntaxhighlight lang='bash'>
i=0
echo $((i++))
echo ${i}
</syntaxhighlight>
displays:
<syntaxhighlight lang='bash'>
0
1
</syntaxhighlight>
Increment the value of a variable, then display t:
<syntaxhighlight lang='bash'>
i=0
echo $((++i))
echo ${i}
</syntaxhighlight>
displays:
<syntaxhighlight lang='bash'>
1
1
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 05:35, 8 May 2020

Internal

Increment an Integer

local i=0
((i++))

Decrement an Integer

local i=1
((i--))

Organizatorium

Display the value of the variable, then increment it:

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

displays:

0
1

Increment the value of a variable, then display t:

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

displays:

1
1