Originally Posted by unSpawn
A=100; B=2; C="0.93"; D=`echo "scale=2;($A-$B)/$C"|bc -l 2>/dev/null`
You have to read the documents that were given. Don't expect to learn bash in 10mn.
Try one of the example and add your little bit, modify the code, see what it gives. It was my way of understanding computer languages. You should practice, not only read.
Meanwhile, try this:
you are now in an interactive calculator
Because bc by default only works on integer
this will tell bc to give you 2 decimals after .
That's for bc
if you want to quit bc, type on a newline
You get back to your shell
Now you have to understand the concept of pipes (read the manuals again).
A pipe is something that will take the result of its command on the left and put it as the input of the command on the right.
In other words, it's like if you were doing command1 which gives result X and then you run command2 and you copy paste X.
For this, command2 has to be a command that is asking for something, like bc, not like ls (when you type ls, your shell doesn't ask you anything)
Now you want to use bc without typing anything. Retype what was above and put a ; between each command
echo "scale=2;98/0.93" | bc -l
so the output of command1 (echo) which is "scale=2;98/0.93" will be injected in command 2 (bc -l)
and your shell displays the result:
That's for specific values, if you want the user to put his values, reread unSpawn line
A=100; B=2; C="0.93"; D=`echo "scale=2;($A-$B)/$C" | bc -l`
I hope you can understand at least the english part of this post