Nn$( expr $n + 1)

HI there

I am trying to understand Shell scripting to create my own, I am attempting a few examples can anyone tell me what this means?

n=$( expr $n + 1)

Tried looking on the internet, but just cannot find its anywhere :frowning: .Help please

expr does as the man page suggests. It evaluates an expression.

$ n=22
$ n=$( expr $n + 1)
$ echo $n
23

$(...) (known as "command substitution") executes the expr command and returns the result back into n.

1 Like
0 ~ $ n=22
0 ~ $ time  n=$( expr $n + 1)

real	0m0.003s
user	0m0.002s
sys	0m0.001s

0 ~ $ time  n=$(( $n + 1))

real	0m0.000s
user	0m0.000s
sys	0m0.000s

0 ~ $ echo $n
24

Just saying :slight_smile:

Some other alternatives:

let n=n+1
((n++))
((n=n+1))
n=$((n+1))

Thank you this has helped me.

:slight_smile: