title: bash handle both starts with non-zero and zero value in if
body: <p>I need to compare two integer values and here is the if condition,</p>
  
  <pre><code>if [[ $VAL -ge 1000 ]] ; then
     #do something 
  fi 
  </code></pre>
  
  <p>But the problem is when it tries to compare with an integer value <code>010</code> got the error saying </p>
  
  <p><code>-bash: 01: value too great for base (error token is "01")</code></p>
  
  <p>I fixed this issue by using <code>$VAL#0</code> in if condition. </p>
  
  <p>But still getting same kind of issue with it tries to compare integer value <code>0010</code> and it fixed with <code>10#${VAL}</code>.</p>
  
  <p>The problem with proper integer values like <code>523</code> and getting below error,</p>
  
  <p><code>[[: #10523: syntax error: operand expected (error token is "#10523")</code></p>
  
  <p>Not sure how to make the if statement works with all the cases. </p>
  
  <p><strong>Update (Solution):</strong></p>
  
  <p>Found the fix.</p>
  
  <pre><code>VAL=$((10#$VAL))
  </code></pre>
  
  <p>Whatever value this will change it to decimal and reassign it to the same variable. </p>