Linux/Bash Shell Script

리눅스 while

준섭이 2023. 12. 26. 11:52
728x90

### bash script에서 while 사용

 

#!/bin/bash

## 기본 사용법
while [조건식] ;
do
	~
done

### ex)
while [ ${input} -le 10 ]
do
	~
done

### 파일을 읽은 후 비교 반복

cat /home/bluemary.out | while read line
do
echo ${line}
    a=`cat /home/athena.out | grep ${line} | wc -l`
    if [ "${a}" != "1" ]; then
    	echo ${line} > /home/nokeys.out
    fi
done

### 무한 반복문
#!/bin/bash

while :
do
	cat "Hello"
    	sleep 2
done