icrementing variables...

Hi all,

My thanks in advance for you guys reading this and for any posts.

I am quite new to shell scripting, and trying to write a script under Redhat Enterprise 3.

Anyhow I was wondering if anyone knew if it was possible to increment a numeric variable by 1. If I was doing it in Java I would just do:

[variable]++

this would increment the variable by 1. Is there a way of doing this in Linux?

Thanks again in advance of any posts,

Marky Mark.

When you ask "is there a way of doing this in Linux," I assume that you are asking whether a Linux/UNIX shell scripting language can do this.

The answer is yes. with either BASH or KSH, you can increment a variable several ways.

X=1
(( X+=1 ))
echo $X
echo $(( X+=10 ))

output:

2
12
var=5
var=`expr $var + 1`