本文介绍了将变量值加1(shell编程)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是shell编程的初学者,这听起来像是一个非常愚蠢的问题,但我似乎无法将变量值增加1。我看过,但仅显示了如何将2个变量加在一起
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 it only shows how to add together 2 variables
尝试了以下方法,但不起作用
I have tried the following methods but it doesnt work
i=0
$i=$i+1 # doesnt work , command not found
echo "$i"
$i='expr $i+1' # doesnt work , command not found
echo "$i"
$i++ # doesnt work , command not found
echo "$i"
如何将变量的值加1?
推荐答案
您可以尝试以下方法:
i=0
i=$((i+1))
这篇关于将变量值加1(shell编程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!