bash - Adding the total of a number all the way back to 1 in unix Shell script -


i trying take number input , add numbers 1 script displays total. e.g. if 5 argument perform 1 + 2 + 3 + 4 + 5 giving answer of 15. help?

here current code:

num1=$1 #adder=1 function total() { while [[ $num1 -gt 0 ]]   addop=$((num1 + (num1-1)))   counter=$((num1--)) done   echo $addop }   total $1 

your script didn't work addop set not running total total of num1 , num1-1 "1" @ exit of loop. fix it, make addop equal num1 , shown below

num1=$1 #adder=1 function total() { while [[ $num1 -gt 0 ]]   addop=$((num1 + (addop)))   counter=$((num1--)) done   echo $addop }   total $1 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

post - imageshack API cURL -

dataset - MPAndroidchart returning no chart Data available -