ループ

for

 IFS='
 '
 for line in `cat /etc/passwd`; do
    echo $line
 done

continue

 for x in 1 2 3; do
    if [ "$x" = "2" ]; then
      continue
    fi
    echo $x
 done
 1
 3

ループ内処理の結果をファイルへリダイレクトする

 for n in 1 2 3; do
    echo DEBUG: $n
 done >> num.txt

while

引数処理

 while [ $# -gt 0 ]; do
    echo $1
    shift
 done

カウントダウン

 try=10
 while [ "$try" -gt 0 ]; do
    try=`expr "$try" - 1`
 done

breakで抜ける

 while : ; do
    if date '+%S' | grep '00'; then
        echo hit
        break
    fi
    echo -n .
    sleep 1
 done

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS

Last-modified: 2015-01-20 (火) 15:01:33