title: How to convert string to integer in Bash?
body: <p>I have found many answers about this on StackOverflow but I can't apply them to my code.</p>
  
  <p>I used this command to get last day of current month:</p>
  
  <pre><code>LASTDAY=`cal $(date +"%m %Y") | grep . | fmt -1 | tail -1`
  </code></pre>
  
  <p>then I use this code:</p>
  
  <pre><code>for i in {1..${LASTDAY}}
  do
      # code for processing here!
  done
  </code></pre>
  
  <p>But always get this warning: 
  <strong>line 12: [: {1..31}: integer expression expected</strong></p>
  
  <p>and <strong>i</strong> is <strong>{1..31}</strong> but I expected <strong>i</strong> is a number in range [1,31]</p>
  
  <p>I have tried this:</p>
  
  <pre><code>LASTDAY=$((LASTDAY+0))
  
  LASTDAY=$( echo "$LASTDAY - 0" | bc )
  
  LASTDAY=$(printf "%d" "$LASTDAY")
  </code></pre>
  
  <p>but it can't solve this problem. What's wrong in my code? and how to fix it?</p>
  
  <p>Thanks in advanced.</p>