[] Shell script for summing all positive integers less than 100 (1 + 2 + 3 + 4 ... + 100) === sum.sh

Summing all positive integers (1 + 2 + 3 + 4 + 100 ...) within 100

[root@VM_0_10_centos shellScript]# cat sum.sh 
#!/bin/bash
# Summing all positive integers less than 100 ( 1 + 2 + 3 + 4 ... + 100 )
# Seq 100 can quickly and automatically generate 100 integers
# Define the initial variable
SUM=0
for i in `seq 100`
do
    # Accumulate
    SUM = $ [SUM + i]
done
echo "(1+2+3+4...+100)总和SUM:$SUM"
[root@VM_0_10_centos shellScript]# ./sum.sh 
( 1 + 2 + 3 + 4 ... + 100 ) the sum of the SUM: 5050

 

Guess you like

Origin www.cnblogs.com/HeiDi-BoKe/p/11672042.html