Several examples of the use of shell scripts to use for while, and expr let parentheses

Several examples of the use of shell scripts to use for while, and expr let parentheses

i=1;((i=i+1));echo $i;
i=1;let 'i++';echo $i;
i=1;i=`expr $i + 1`;echo $i;
i=1;i=$(expr $i + 1);echo $i;
i=1;i=$((i + 1));echo $i;

These results are 2

for ((i=0;i<5;i++)); do echo $i;done
for i in $(seq 0 4); do echo $i;done
for i in `seq 0 4`; do echo $i;done
for i in {1..4};do echo $i;done

These results are printing a sequence number

int=1
while(( $int<=5 ))
do
    echo $int
    let "int++"
done

These results also print a sequence number

i=1;while (($i < 10));do echo $i;((i++)); done;
i=1;while [[ $i -lt 10 ]];do echo $i;((i++)); done;
i=1;while [ $i -lt 10 ];do echo $i;((i++)); done;
i=1;while [ $i -lt 10 ];do echo $i;((i=i+1)); done;
i=1;s=0;while [ $i -lt 10 ];do s=`expr $s + $i`;echo ${i}:${s};((i++)); done;

These are used in various ways while the print sequence number

if [ $(ps -ef | grep -c "ssh") -gt 1 ]; then echo "true"; fi
a=10
b=20
if [ $a == $b ]
then
   echo "a 等于 b"
elif [ $a -gt $b ]
then
   echo "a 大于 b"
elif [ $a -lt $b ]
then
   echo "a 小于 b"
else
   echo "没有符合的条件"
fi

The above is of use if

Published 48 original articles · won praise 3 · views 20000 +

Guess you like

Origin blog.csdn.net/chscomfaner/article/details/103885658