I have to variables and I want to find the value of one divided by the other. What commands should I use to do this?
Something else you could do using raytrace's answer. You could use the stdout of another shell call using backticks to then do some calculations. For instance I wanted to know the file size of the top 100 lines from a couple of files. The original size from wc -c
is in bytes, I want to know kilobytes. Here's what I did:
echo `cat * | head -n 100 | wc -c` / 1024 | bc -l
Example of integer division using bash to divide $a by $b:
echo $((a/b))
you can also use perl -e
perl -e 'print 67/8'
I assume that by Linux console you mean Bash.
If X
and Y
are your variables, $(($X / $Y))
returns what you ask for.
echo 5/2 | bc -l
2.50000000000000000000
this '-l' option in 'bc' allows floating results
You should try to use:
echo "scale=4;$variablename/3"|bc