bash 스크립트 라인단위로 읽기에 궁금한점인데요

laverrice의 이미지

#!/bin/bash

exec < $test

while read line
do
echo $line #여기서 $line은 무엇을 의미하나요?
done

이렇게 하면 되는건가요?
그리고 가장 중요한건
for test in `test.txt`
do
echo $test
done
이런식으로하면 test.txt가 $test에 자동 저장되잖아요
그런데 while문에서는 어떻게 변수에 넣나요?

dormael의 이미지

http://www.gnu.org/s/bash/manual/bash.html#Bash-Builtins

여기에서 read에 관해서 읽어보시면 이해가 되실것 같아요.

저도 아무 생각없이 read line이라고 쓰고 있었는데...

read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]

One line is read from the standard input, or from the file descriptor fd supplied as an argument to the -u option, and the first word is assigned to the first name, the second word to the second name, and so on, with leftover words and their intervening separators assigned to the last name. If there are fewer words read from the input stream than names, the remaining names are assigned empty values. The characters in the value of the IFS variable are used to split the line into words. The backslash character ‘\’ may be used to remove any special meaning for the next character read and for line continuation. If no names are supplied, the line read is assigned to the variable REPLY. The return code is zero, unless end-of-file is encountered, read times out (in which case the return code is greater than 128), or an invalid file descriptor is supplied as the argument to -u.

-- Signature --
青い空大好き。
蒼井ソラもっと好き。
파란 하늘 너무 좋아.
아오이 소라 더좋아.