我想通过测试对我的 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