2

I'd like to sort my figlet fonts with testing, so I've decided to make a script, which will demonstrate figlet font one by one and will delete fonts I don't like. I've tried to find the solution for correct if-then condition inside while loop, but couldn't find one. Here's the script itself, but for now it just provides examples of all the fonts in the single scroll:

#!/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
3

The original problem, is that content of your file list is being fed to read decision and while cycle doesn't work as you expect. Though why do you need a list at all?

Better to iterate through files with for cycle.

#!/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
  • @FCW If one of the answers solved your issue, please take a moment to accept it by clicking on the checkmark on the left. That will mark the question as answered and is the way that thanks are conveyed on the Stack Exchange sites. – terdon Apr 22 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.