title: Shell Script: Hexadecimal Loop
body: <p>I am trying to learn shell script and writing a simple script to increment Hex values in the loop.</p>
  
  <p>Here is my script:</p>
  
  <pre><code>increment=0x0001
  handle=0x0001
  
  for((i=1;i&lt;=20;i++))
  do
     echo $handle
     handle=$(($handle + $increment))
     handle=$(printf '%x' $handle)
  done
  </code></pre>
  
  <p>Here is my output:</p>
  
  <pre><code>0x0001
  2
  3
  4
  5
  6
  7
  8
  9
  a
  1
  2
  3
  4
  5
  6
  7
  8
  9
  a
  </code></pre>
  
  <p>It is working fine till 10th iteration but after that it is starting from 1 again.</p>
  
  <p>Can any one let me know my mistake?</p>
  
  <p>EDIT: After removing <code>handle=$(printf '%x' $handle)</code> line output is:</p>
  
  <pre><code>0x0001
  2
  3
  4
  5
  6
  7
  8
  9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  </code></pre>
  
  <p>Actually I want output in HEX only.</p>