Is it bad to use the conditions for `find`ing the directories and to `cd` multiple specific folders of a found directory to call the function?
I would like to find an icons theme somewhere to cd
and then to replace and add/insert in all SVG files in multiple specific folders.
I am not sure if my bash/shell codes are bad and inelegant in your eyes.
- Firstly begins the function
go_dir_to_breeze
. You can see the conditions in the end of code, in the which it will locate the existent icons theme somewhere. If it is found, you will enter in the functiongo_dir_to_breeze
and begin the item (2). - After found successfully, you are entering in the function
change_colour()
, which will begin thesed
to replace and string, callingfoo.pl
, but instead, it will hear to the variable of the chosen colour/gradient in the conditions before beginning to callchange_colour()
. If the colour/gradient is found, it will begin to callfoo.pl
to replace and insert. - The terminal will change the directory with
cd
, which will call the functionchange_colour()
.
For example:
echo "Which type of colour do you prefer? Write the nummber"
echo "1) solid 2) gradient"
read type
if [$type = "1"]; then
echo "Write one of these colours to choose your favourite:"
echo "black gold green\n grey orange purple\n red yellow"
read color
else
echo "Write one of these letters to choose your favourite gradient:"
echo "a) telinkrin b) arrogrin c) minoan"
read color
fi
go_dir_to_breeze()
{
change_colour()
{
for f in *svg; do
case "$color" in
a)
perl gradient1.pl "$f" > tmpFile && mv tmpFile "$f"
;;
b)
perl gradient2.pl "$f" > tmpFile && mv tmpFile "$f"
;;
c)
perl gradient3.pl "$f" > tmpFile && mv tmpFile "$f"
;;
black)
perl black.pl "$f" > tmpFile && mv tmpFile "$f"
;;
gold)
perl gold.pl "$f" > tmpFile && mv tmpFile "$f"
;;
green)
perl green.pl "$f" > tmpFile && mv tmpFile "$f"
;;
grey)
perl grey.pl "$f" > tmpFile && mv tmpFile "$f"
;;
orange)
perl orangle.pl "$f" > tmpFile && mv tmpFile "$f"
;;
purple)
perl purple.pl "$f" > tmpFile && mv tmpFile "$f"
;;
red)
perl red.pl "$f" > tmpFile && mv tmpFile "$f"
;;
esac
done
}
cd apps='apps/16'
change_colour
cd ..
cd places='places/16'
change_colour
cd ..
cd mimetypes='mimetypes/16'
change_colour
}
if [ find /home/$USER/.icons/breeze ]; then
go_dir_to_breeze
elif [ find /home/$USER/local/share/icons/breeze ]; then
go_dir_to_breeze
# Observe that to change the colour of icons, it is required to run as root
elif [ find /usr/share/icons/breeze ]; then
go_dir_to_breeze
else
echo "Icons theme Breeze does not exist!"
fi
Are the conditions of find
ing the directories of icons theme good and bad? And is cd
ing multiple specific folders to call the function change_colour
good or bad?
So maybe the user can receive the errors in these cases.