How do I echo a sum of a variable and a number?

前端 未结 9 679
眼角桃花
眼角桃花 2020-12-30 05:03

I have a variable x=7 and I want to echo it plus one, like echo ($x+1) but I\'m getting:

bash: syntax error near unexpected

相关标签:
9条回答
  • 2020-12-30 05:49

    You can also use the bc utility:

    $ x=3;
    $ echo "$x+5.5" | bc
    8.5
    
    0 讨论(0)
  • 2020-12-30 05:52

    Try this way:

    echo $(( $X + 1 ))
    
    0 讨论(0)
  • 2020-12-30 05:57

    We use expr for that:

    echo `expr $x + 1`
    
    0 讨论(0)
提交回复
热议问题