0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

目的

  • ShellScript Bashにて指定回数処理を繰り返すfor文の書き方をまとめる

書き方の例

  • 下記に指定回数処理を繰り返すfor文の例を記載する。
  • ((i=0; i<指定の回数; i++))((iは0から始まる; この回数に達したら処理は終了; 一回の処理ごとにiに1を足す))ということである
#!/bin/bash

for ((i=0; i<指定の回数; i++)); do
  指定回数繰り返したい処理
done

より具体的な書き方の例

  • 下記に期待値の出力を記載する。
*
**
***
****
*****
  • 下記に前述の期待値の出力を行う処理を記載する。
#!/bin/bash

FOO_1="*"
FOO_2="*"
for ((i=0; i<5; i++)); do
  echo "${FOO_1}"
  FOO_1="${FOO_1}""${FOO_2}"
done
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?