Increment variable value by 1 ( shell programming)

前端 未结 5 2025
太阳男子
太阳男子 2020-12-24 11:28

I am a beginner to shell programming and it sounds like a very stupid question but i cant seem to be able to increase the variable value by 1. I have looked at tutorial but

5条回答
  •  离开以前
    2020-12-24 11:43

    These are the methods I know:

    ichramm@NOTPARALLEL ~$ i=10; echo $i;
    10
    ichramm@NOTPARALLEL ~$ ((i+=1)); echo $i;
    11
    ichramm@NOTPARALLEL ~$ ((i=i+1)); echo $i;
    12
    ichramm@NOTPARALLEL ~$ i=`expr $i + 1`; echo $i;
    13
    

    Note the spaces in the last example, also note that's the only one that uses $i.

提交回复
热议问题