Linux シェルスクリプト continueでループの先頭に戻るサンプル

環境
# cat/etc/redhat-release
AlmaLinux release 8.7 (Stone Smilodon)

構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
if [条件式 ]; then
continue
fi
if [条件式 ]; then continue fi
if [条件式 ]; then
  continue
fi

continueでループ処理の先頭に戻ります。

サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/bin/bash
for ((i=10; i<13; i++))
do
if [ $i -eq 11 ]; then
continue
fi
echo $i
done
#!/bin/bash for ((i=10; i<13; i++)) do if [ $i -eq 11 ]; then continue fi echo $i done
#!/bin/bash

for ((i=10; i<13; i++))
do
    if [ $i -eq 11 ]; then
      continue
    fi
    echo $i
done

実行結果
10 12

AlmaLinux

Posted by arkgame