0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

シェルスクリプトの条件分岐と繰り返し

Posted at

はじめに

条件分岐について調べたので、これに繰り返しを加えたものを作りたいと思いました。

条件分岐と繰り返しの組み合わせ

今回は1から20までを繰り返します。
17までは残留、18以下は降格という出力をする内容になります。

記載すると以下のようになります。

#!/bin/bash
for i in {1..20}
do 
	if [ "$i" -le 17 ]; then
		echo "残留"
		continue
	elif [ "$i" -ge 18 ]; then
		echo "降格"
		continue
	fi
done

出力結果は以下の通りです。

残留
残留
残留
残留
残留
残留
残留
残留
残留
残留
残留
残留
残留
残留
残留
残留
残留
降格
降格
降格

残留が17、降格が3つ出力されています。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?