Help us understand the problem. What is going on with this article?

ShellScript Bash for文の書き方

目的

  • 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
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away