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

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

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

View Article



Answer by Hola Soy Edu Feliz Navidad for Calculate variable, and output it to...

I would use (as was mentioned before) rownum=$((nextnum+1)) or ((rownum=nextnum+1)) but if you prefer an standard command you can use the let command, like let rownum=$nextnum+1

View Article

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

You can also use built in arithmetic in bash: rownum=$((nextnum+1)) which would be slightly faster.

View Article

Answer by manatwork for 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...

View Article

Calculate variable, and output it to another variable

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

View Article

Browsing all 5 articles
Browse latest View live




Latest Images