title: Floating point results in Bash integer division
body: <p>I have a backup script on my server which does cron jobs of backups, and sends me a summary of  files backed up, including the size of the new backup file. As part of the script, I'd like to divide the final size of the file by (1024^3) to get the file size in GB, from the file size in bytes. </p>
  
  <p>Since bash does not have floating point calculation, I am trying to use pipes to bc to get the result, however I'm getting stumped on basic examples.</p>
  
  <p>I tried to get the value of Pi to a scale, however,</p>
  
  <p>even though the following works:</p>
  
  <pre><code>~ #bc -l
  bc 1.06.95
  Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
  This is free software with ABSOLUTELY NO WARRANTY.
  For details type `warranty'.
  4/3
  1.33333333333333333333
  22/7
  3.14285714285714285714
  q
  0
  quit
  </code></pre>
  
  <p>A non interactive version does not work:</p>
  
  <pre><code>#echo $(( 22/7 )) | bc
  3
  </code></pre>
  
  <p>This works:</p>
  
  <pre><code>#echo '22/7' | bc -l
  3.14285714285714285714
  </code></pre>
  
  <p>But I need to use variables. So it doesnt help that the following does not work:</p>
  
  <pre><code>#a=22 ; b=7
  #echo $(( a/b )) | bc -l
  3
  </code></pre>
  
  <p>I'm obviously missing something in the syntax for using variables in Bash, and could use with some 'pointers' on what I've misunderstood.</p>
  
  <p>As DigitalRoss said, I can use the following:</p>
  
  <pre><code>#echo $a / $b | bc -l
  3.14285714285714285714
  </code></pre>
  
  <p>However I cant use complex expressions like:</p>
  
  <pre><code>#echo $a / (( $b-34 )) | bc -l
  -bash: syntax error near unexpected token `('
  #echo $a / (( b-34 )) | bc -l
  -bash: syntax error near unexpected token `('
  #echo $a / (( b-34 )) | bc -l
  -bash: syntax error near unexpected token `('
  </code></pre>
  
  <p>Can someone give me a working correct syntax for getting floating point results with complicated arithmetic expresssions?</p>