<span style=
"color: #008080"
> 1</span> <span style=
"color: #000000"
>例3
</span><span style=
"color: #008080"
> 2</span> <span style=
"color: #000000"
>#只能用[[ ]] 可以进行进制转换比较
</span><span style=
"color: #008080"
> 3</span>
<span style=
"color: #008080"
> 4</span> <span style=
"color: #0000ff"
>decimal</span>=<span style=
"color: #800080"
>15</span><span style=
"color: #000000"
> #十进制
</span><span style=
"color: #008080"
> 5</span> octial=<span style=
"color: #800080"
>017</span><span style=
"color: #000000"
> #八进制
</span><span style=
"color: #008080"
> 6</span> hex=<span style=
"color: #800080"
>0x0f</span><span style=
"color: #000000"
> #十六进制
</span><span style=
"color: #008080"
> 7</span> <span style=
"color: #0000ff"
>
if
</span> [ <span style=
"color: #800000"
>
"</span><span style="
color: #800000
">$decimal</span><span style="
color: #800000
">"
</span> -eq <span style=
"color: #800000"
>
"</span><span style="
color: #800000
">$octal</span><span style="
color: #800000
">"
</span><span style=
"color: #000000"
> ]
</span><span style=
"color: #008080"
> 8</span> <span style=
"color: #0000ff"
>then</span>
<span style=
"color: #008080"
> 9</span> <span style=
"color: #0000ff"
>
echo
</span> <span style=
"color: #800000"
>
"</span><span style="
color: #800000
">$decimal equals $octal</span><span style="
color: #800000
">"
</span>
<span style=
"color: #008080"
>10</span> <span style=
"color: #0000ff"
>
else
</span>
<span style=
"color: #008080"
>11</span> <span style=
"color: #0000ff"
>
echo
</span> <span style=
"color: #800000"
>
"</span><span style="
color: #800000
">$decimal is not equal to $octal</span><span style="
color: #800000
">"
</span> # <span style=
"color: #800080"
>15</span> is not equal to <span style=
"color: #800080"
>017</span>
<span style=
"color: #008080"
>12</span> <span style=
"color: #0000ff"
>fi</span> <br> # 不能用单括号[ ]计算!
<span style=
"color: #008080"
>13</span> <span style=
"color: #0000ff"
>
if
</span> [[ <span style=
"color: #800000"
>
"</span><span style="
color: #800000
">$decimal</span><span style="
color: #800000
">"
</span> -eq <span style=
"color: #800000"
>
"</span><span style="
color: #800000
">$octal</span><span style="
color: #800000
">"
</span><span style=
"color: #000000"
> ]]
</span><span style=
"color: #008080"
>14</span> <span style=
"color: #0000ff"
>then</span>
<span style=
"color: #008080"
>15</span> <span style=
"color: #0000ff"
>
echo
</span> <span style=
"color: #800000"
>
"</span><span style="
color: #800000
">$decimal equals $octal</span><span style="
color: #800000
">"
</span> # <span style=
"color: #800080"
>15</span> equals <span style=
"color: #800080"
>017</span>
<span style=
"color: #008080"
>16</span> <span style=
"color: #0000ff"
>
else
</span>
<span style=
"color: #008080"
>17</span> <span style=
"color: #0000ff"
>
echo
</span> <span style=
"color: #800000"
>
"</span><span style="
color: #800000
">$decimal is not equal to $octal</span><span style="
color: #800000
">"
</span>
<span style=
"color: #008080"
>18</span> <span style=
"color: #0000ff"
>fi</span> # 要用双括号[[ ]]计算!
<span style=
"color: #008080"
>19</span> <span style=
"color: #0000ff"
>
if
</span> [[ <span style=
"color: #800000"
>
"</span><span style="
color: #800000
">$decimal</span><span style="
color: #800000
">"
</span> -eq <span style=
"color: #800000"
>
"</span><span style="
color: #800000
">$hex</span><span style="
color: #800000
">"
</span><span style=
"color: #000000"
> ]]
</span><span style=
"color: #008080"
>20</span> <span style=
"color: #0000ff"
>then</span>
<span style=
"color: #008080"
>21</span> <span style=
"color: #0000ff"
>
echo
</span> <span style=
"color: #800000"
>
"</span><span style="
color: #800000
">$decimal equals $hex</span><span style="
color: #800000
">"
</span> # <span style=
"color: #800080"
>15</span> equals <span style=
"color: #800080"
>0x0f</span>
<span style=
"color: #008080"
>22</span> <span style=
"color: #0000ff"
>
else
</span>
<span style=
"color: #008080"
>23</span> <span style=
"color: #0000ff"
>
echo
</span> <span style=
"color: #800000"
>
"</span><span style="
color: #800000
">$decimal is not equal to $hex</span><span style="
color: #800000
">"
#<span
class
=
"fontstyle0"
>[[
$hexadecimal
]]也能计算<br></span></span>
<span style=
"color: #008080"
>24</span> <span style=
"color: #0000ff"
>fi</span>