1
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 5 years have passed since last update.

bash の for ループ

Last updated at Posted at 2016-12-11

こうやって書ける

#!/bin/bash

for((i=0;i<5;i++)){
    echo $i
}

スペース入れてもOK

#!/bin/bash

for (( i = 0 ; i < 5 ; i ++ )) {
    echo $i
}

出典
http://qiita.com/b4b4r07/items/e56a8e3471fb45df2f59

man bash 抜粋

for (( expr1 ; expr2 ; expr3 )) ; do list ; done
    First,  the  arithmetic  expression  expr1  is  evaluated according to the rules
    described below under ARITHMETIC EVALUATION.  The arithmetic expression expr2 is
    then evaluated repeatedly until it evaluates to zero.  Each time expr2 evaluates
    to a non-zero value, list is executed and the  arithmetic  expression  expr3  is
    evaluated.   If  any  expression is omitted, it behaves as if it evaluates to 1.
    The return value is the exit status of the last command in  list  that  is  exe-
    cuted, or false if any of the expressions is invalid.

; do list ; done の部分がなんで { list } でいいのか謎。

1
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
1
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?