The statement:
Because of that, any variables you create in the script aren't available to the subshell command.
is false. The scope of a variable defined in the parent shell is the entire script (including subshells created with command substitution).
Running:
#!/bin/bash
var=5.5555
ans1=$(echo $var)
ans2=$(var=6; echo $var)
echo $ans1
echo $ans2
will give the result:
5.5555
6
$var is resolved by the subshell:
- if no local variable is specified, the value of three global variable is used
- if a local variable is specified, it uses its value
See also the example 21-2.