bash - Dividing double-precision shell variables in a shell script -


i working shell scripting on linux.

i have 2 double variables , want divide them, , put results variable.

i tried following (does not work) :

#!/bin/bash a=333.33 b=111.11 c="$a / $b" | bc -l 

although following work:

#!/bin/bash a=333.33 b=111.11 echo "$a / $b" | bc -l 

what doing wrong?

thanks matt

pipes work on output streams, and:

c="$a / $b" | bc -l 

does not send "$a / $b" output stream, instead sends eof.

you can this:

c=$(echo "$a / $b" | bc -l) 

to result c.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -