![디렉터리 및 조건의 파일을 사용하여 명령을 실행하는 Bash 스크립트](https://linux55.com/image/152239/%EB%94%94%EB%A0%89%ED%84%B0%EB%A6%AC%20%EB%B0%8F%20%EC%A1%B0%EA%B1%B4%EC%9D%98%20%ED%8C%8C%EC%9D%BC%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%EB%AA%85%EB%A0%B9%EC%9D%84%20%EC%8B%A4%ED%96%89%ED%95%98%EB%8A%94%20Bash%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8.png)
테스트를 통해 Figlet 글꼴을 정렬하고 싶었기 때문에 Figlet 글꼴을 하나씩 살펴보고 마음에 들지 않는 글꼴을 제거하는 스크립트를 만들기로 결정했습니다. while 루프 내에서 올바른 if-then 조건에 대한 해결책을 찾으려고 하는데 찾을 수 없습니다. 다음은 스크립트 자체이지만 현재는 단일 스크롤에 있는 모든 글꼴의 예만 제공합니다.
#!/bin/bash
#script to test figlet fonts
rm /usr/share/figlet/list.txt #delete old list
ls /usr/share/figlet > /usr/share/figlet/list.txt #create new list
filename='/usr/share/figlet/list.txt'
n=1
while read line; do
figlet -f $line Figlet
echo -e "Press 0 if you don't like it, font will be deleted"
read decision
if [ "$decision" = "0" ]; then
rm "/usr/share/figlet/$line"
echo -e "Font deleted"
else
echo -e "Font saved"
fi
n=$((n+1))
done < $filename
답변1
초기 문제는 파일 목록의 내용이 입력되고 루프가 예상대로 작동하지 않는다는 것 read decision
입니다 while
. 그런데 왜 목록이 필요한가요?
파일을 반복하는 것이 좋습니다 for
.
#!/bin/bash
for font in /usr/share/figlet/*; do
figlet -f "$font" Figlet
echo -e "Press 0 if you don't like it, font will be deleted"
read decision
if [ "$decision" = "0" ]; then
rm "$font"
echo -e "Font deleted"
else
echo -e "Font saved"
fi
done