我想通过测试对我的小雕像字体进行排序,所以我决定制作一个脚本,它将逐一演示小字体,并删除我不喜欢的字体。我试图找到正确的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发布于 2019-04-22 10:52:38
最初的问题是,您的文件列表中的内容被输入到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
donehttps://unix.stackexchange.com/questions/513783
复制相似问题