Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error: operand expected (error token is "+")

Tags:

bash

unix

I'm writing a script in bash and I get this error:

./P4.1: line 10: +: syntax error: operand expected (error token is "+")

And this is my code:

#!/bin/bash
read string
echo $string >| temp
num1= cut -d" " -f1 temp
num2= cut -d" " -f2 temp
num3= cut -d" " -f3 temp
while [ $num1 -gt $num3 ]
do
        echo $num1
        num1=$[$num1+$num2]
done

What's wrong and how do I fix it? Thanks.

like image 569
shoham Avatar asked Nov 24 '13 16:11

shoham


1 Answers

Combination of ceving and Tomek's:

#!/bin/bash
read num1 num2 num3
while [ $num1 -lt $num3 ]
do
    echo $num1
    num1=$((num1+num2))
done
like image 94
Blue Ice Avatar answered Sep 22 '22 14:09

Blue Ice