Syntax error: operand expected (error token is “+”)

后端 未结 3 501
谎友^
谎友^ 2021-01-04 03:40

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 m

相关标签:
3条回答
  • 2021-01-04 03:58

    Use round parenthesis for numeric computations:

    num1=$((num1 + num2))
    
    0 讨论(0)
  • 2021-01-04 04:07

    Combination of ceving and Tomek's:

    #!/bin/bash
    read num1 num2 num3
    while [ $num1 -lt $num3 ]
    do
        echo $num1
        num1=$((num1+num2))
    done
    
    0 讨论(0)
  • 2021-01-04 04:07
    #!/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=$(expr "${num1}" + 1)
    done
    

    also, quote and brace your variables. :D

    0 讨论(0)
提交回复
热议问题