📚 [Bash] 파일 읽어들여 처리하기

Category: Bash | 📅 August 08, 2019

준비물

  • 읽어들일 파일 : aaa.txt
  • 수행할 스크립트 : while.sh

aaa.txt 만들기

$vi aaa.txt

aaa
bbb
ccc

쉘 스크립트 작성

$vi while.sh

#!/bin/bash

SOURCE=aaa.txt

while read line
do
  echo $line
done < $1

해당 내용을 파일로 저장하고 싶을 때는 아래와 같이 수정한다.

$vi while.sh

#!/bin/bash

SOURCE=aaa.txt
RESULT = ./result.txt

while read line
do
  echo $line >> $RESULT
done < $1

실행하기

$while.sh aaa.txt
🏷️ Tags
  • #Shell  
  • #Linux  
  • #Bash