Why does
a2=100.
echo 1.1*$a2|bc
work on the terminal, but the 3 variants in the following script don't:
a2=100.
echo "
1.1*$a2|bc
$(1.1*$a2|bc)
$((1.1*$a2|bc))
">x.sh
Because you didn't put echo statements in the script code piped to x.sh. The second variant requires an additional echo inside the subshell command $(...). And the third variant is not valid, because $((...)) arithmetic expansion doesn't work on floating point numbers.
a2=100.
echo "
echo 1.1*$a2|bc;
echo $(echo 1.1*$a2|bc);
">x.sh
Result:
# sh x.sh
110.0
110.0