![bash는 디렉터리의 모든 파일을 반복한 다음 각 파일의 줄을 반복합니다.](https://linux55.com/image/146227/bash%EB%8A%94%20%EB%94%94%EB%A0%89%ED%84%B0%EB%A6%AC%EC%9D%98%20%EB%AA%A8%EB%93%A0%20%ED%8C%8C%EC%9D%BC%EC%9D%84%20%EB%B0%98%EB%B3%B5%ED%95%9C%20%EB%8B%A4%EC%9D%8C%20%EA%B0%81%20%ED%8C%8C%EC%9D%BC%EC%9D%98%20%EC%A4%84%EC%9D%84%20%EB%B0%98%EB%B3%B5%ED%95%A9%EB%8B%88%EB%8B%A4..png)
나는 가지고있다
urls1.txt
urls2.txt
urls3.txt
등.
어떻게 해당 디렉터리의 모든 파일을 반복하고 해당 파일의 각 줄을 반복할 수 있나요?
답변1
귀하가 작성한 질문에 답하려면 다음을 수행하십시오.
#!/bin/bash
for file in /path/to/files/*.txt; do
# This will loop through each .txt file in the directory
# setting the full file path to $file
# I recommend adding the .txt if you know all your files
# will have that extension otherwise the following is fine:
# for file in /path/to/files/*; do
while read -r line; do
# This will loop through each line of the current file
# and set the full line to the $line variable
command "$line"
done < "$file"
done
코드 내의 주석에 설명되어 있습니다.