Script B should work like -bc does.
Example:
echo `echo "4^3.5" | -scriptb.sh`
[result]
Edit: I just came up with a part of the solution by myself and thought I'd share it:
# ScriptA.sh
echo `echo "44 33" | bash ScriptB.sh`
# ScriptB.sh
read x y
echo $(($x+$y))
Output:
bash ScriptA.sh
77
The next problem is my ScriptB.sh looks a little more like this:
# ScriptB.sh
until [[ 1 = 2 ]]; do
echo Enter x and y
read x y
if [[ x = q ]]; then
break 1
fi
echo $(($x+$y))
done
This is in order to allow multiple inputs, if I want to use ScriptB manually. If I let ScriptA use ScriptB in the above mentioned way the output looks like this:
bash ScriptA.sh
b.sh: line 9: +: syntax error: operand expected (error token is "+")
Enter x and y 77 Enter x and y
It seems to be the case that after ScriptA inputs 44 and 33 and hits enter, like it should, but it hits enter right away a second time triggering the syntax error message and ending ScriptB. This is suboptimal, because in the case of the real ScriptB it will enter a "(standard_in) 1: parse error"-chain, resulting in no result at all. The solution to this problem would be by teaching ScriptA to read what ScriptB promts as result and ending it right after this. Or making it enter "q" as a second input instead of just hitting enter.
Edit 2:
Ok. Got it. Script A should look like this in order to work as desired:
e=2.7182818285
pi=3.141
a=$(printf "$e $pi \n q \n" | bash ScriptB.sh)
a=${a:14:20}
echo $a