for i in {0..9} do
T=$(bc<<<"8+$i*0.5")
echo $T
done
I get :
syntax error near unexpected token `T=$(bc<<<"8+$i*0.5")'
I believe the problem is the $i
. What am I doing wrong?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityThe problem is not $i
, the problem is in your for
construct syntax. You need a newline or ;
before do
(if used right after the for
declaration):
for i in {0..9}; do
T=$(bc <<<"8+$i*0.5")
echo "$T"
done
Or
for i in {0..9}
do
T=$(bc <<<"8+$i*0.5")
echo "$T"
done
For clarity, it's better to use whitespace before the here string (<<<
) (and similar).
Although not strictly necessary in this case, you should quote your variable expansions.