13,420
edits
Changes
→Additional Loop Statements
The older method is to use the '''expr''' command.
''Example:''
<pre span style="font-weight:bold;font-family:courier;">num1=5;num2=10<br>result=$(expr $num1 + $num2)<br>echo "$num1 + $num2 = $result"<br>
5 + 10 = 15
</prespan>
A short-cut to convert text values to binary numbers is to contain within a double set of round brackets: '''(( ))'''
''Example:''
<pre span style="font-weight:bold;font-family:courier;">num1=5;num2=10<br>((result $num1 - $num2))<br>echo "$num1 - $num2 = $result"<br>
5 - 10 = -5
</prespan>
Alternative Example:
<pre span style="font-weight:bold;font-family:courier;">num1=5;num2=10<br>echo "$num1 x $num2 = $((num1 * num2))"<br>
5 x 10 = 50
</prespan>
''Example using a Loop:''
<pre span style="font-weight:bold;font-family:courier;">value=1<br>while [ $value -le 5 ]<br>do<br> echo "$value"<br> ((value=value+1)) # could also use ((value++))<br>done<br>1<br>2<br>3<br>4<br>
5
</prespan>
===Using Startup Files===