Im currently stuck trying to solve a small problem where I want to pass a variable to the basic calculator program and safe the outcome of the calculation. so my idea is to pipe input in form of echo into bc and assign the outcome of the calculation to a variable to echo it afterwards as demonstrated on console:
I came up with the following code:
#!/bin/bash
# sqrt test
a=20736
echo "a is $a" # will print a is 20736
b=sqrt"($a)"|bc
echo "b is $b" # will print b is
echo sqrt"($a)"|bc # will print 144
I don't understand why the output from echo "b is $b"
will be "b is" without actually printing the calculated value. What am i missing?