本文介绍了将变量值加1(shell编程)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是shell编程的初学者,这听起来像是一个非常愚蠢的问题,但是我似乎无法将变量值增加1.我看过 tutorialspoint的 Unix/Linux Shell编程指南,但仅显示了如何将两个变量加在一起

I am a beginner in shell programming, and it sounds like a very stupid question but I can't seem to be able to increase the variable value by 1. I have looked at tutorialspoint's Unix / Linux Shell Programming tutorial but it only shows how to add together two variables.

我尝试了以下方法,但是它们不起作用:

I have tried the following methods but they don't work:

i=0

$i=$i+1 # doesn't work: command not found

echo "$i"

$i='expr $i+1' # doesn't work: command not found

echo "$i"

$i++ # doesn't work*, command not found

echo "$i"

如何将变量的值增加1?

推荐答案

您可以尝试以下方法:

i=0
i=$((i+1))

这篇关于将变量值加1(shell编程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:47
查看更多