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

Calculate variable, and output it to another variable

$
0
0

The only calculator I know is bc. I want to add 1 to a variable, and output to another variable.

I got the nextnum variable from counting string in a file:

nextnum=`grep -o stringtocount file.tpl.php | wc -w`

Lets say the nextnum value is 1. When added with 1, it will become 2. To calculate, I run:

rownum=`$nextnum+1 | bc`

but got error:

1+1: command not found

I just failed in calculation part. I've tried changing the backtick but still not works. I have no idea how to calculate variables and output it to another variable.


Viewing all articles
Browse latest Browse all 5

Trending Articles



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