Calculate variable, and output it to another variable

The substring inside the ` ` must be a valid command itself:

rownum=`echo $nextnum+1 | bc`

But is preferable to use $( ) instead of ` `:

rownum=$(echo $nextnum+1 | bc)

But there is no need for bc, the shell is able to do integer arithmetic:

rownum=$((nextnum+1))

Or even simpler in bash and ksh:

((rownum=nextnum+1))

You can also use built in arithmetic in bash:

rownum=$((nextnum+1))

which would be slightly faster.


Absolutely right and complete the suggested solutions, just to mention the way it has to be done in former times when only the Bourne-Shell was available, that's the way it likes it:

rownum=`expr $nextnum + 1`