구조

while  <명령어(주로 조건식)>
do
   반복처리
done

 

홀수 출력하기 예시

while-example.sh

#!/bin/bash

i = 1
while [ "$i" -le 10 ]      # 10 이하까지 반복
do
    echo "$i"
    i = $((i+2))               # 산술연산자
done

 

 

산술연산자

$ i=10
$ echo $(( i + 1 ))
11
$ echo $(( i / 2))
5
$ echo $(( i * 2 ))
20
$ echo $(( i ** 2))
100

+ Recent posts