1
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?

0
3

The 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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.