Quantcast
Channel: Calculate variable, and output it to another variable - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 5

Answer by manatwork for Calculate variable, and output it to another variable

$
0
0

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))

Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>