しばらくの間、使用するシェルスクリプトの使用のいくつかの例、およびexprの括弧をしましょう
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;
これらの結果は、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
これらの結果は、シーケンス番号を印刷しています
int=1
while(( $int<=5 ))
do
echo $int
let "int++"
done
また、これらの結果は、シーケンス番号を印刷します
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;
これらは、印刷シーケンス番号ながら、さまざまな方法で使用されています
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
使用の上である場合