Quiz Assessment
#!/bin/bash
tops=("T-shirt" "Blouse" "Sweater" "Jacket" "Hoodie")
bottoms=("Jeans" "Skirt" "Trousers" "Shorts" "Leggings")
shoes=("Sneakers" "Boots" "Sandals" "Flats" "High heels")
accessories=("Necklace" "Hat" "Watch" "Sunglasses" "Belt")
days=("Monday" "Tuesday" "Wednsday" "Thursday" "Friday")
#########################
## FUNCTION DEFINITION ##
#########################
function selectWardrobe(){
echo "Now selecting weekly wardrobe"
for day in "${days[@]}";do
r_top=${tops[$((RANDOM % ${#tops[@]}))]}
r_bot=${bottoms[$((RANDOM % ${#bottoms[@]}))]}
r_sho=${shoes[$((RANDOM % ${#shoes[@]}))]}
one_acc=${accessories[$((RANDOM % ${#accessories[@]}))]}
two_acc=${accessories[$((RANDOM % ${#accessories[@]}))]}
echo "On $day, you should wear: $r_top, $r_bot and $r_sho "
echo "Pair with: $one_acc 1 and $two_acc 2"
echo
done
}
#########################
## FUNCTION DEFINITION ##
#########################
function outfitSelection(){
while true; do
read -p "Accepting an integer between 1-52: " numweek
if [[ $numweek -gt 1 && $numweek -lt 52 ]]; then
echo "Generating outfit selection for $numweek weeks"
declare -i workWeek=0
while (( $workWeek < $numweek )); do
echo "Week $((workWeek+1)) Wardrobe: "
selectWardrobe
((workWeek++))
done
break
else
echo "Integer must be between 1-52"
fi
done
echo "Enjoy $numweek weeks of outfit selections"
}
outfitSelection 4 > monthlyOutfit.txt # 4 is the argument
input_file="monthlyOutfit.txt"
if [[ -e "$input_file" ]]; then
# Read lines from the file
while IFS= read -r line || [ -n "$line" ]; do # -r for not treating special characters
echo "$line"
done < "$input_file"
else
echo "File not found: $input_file"
fi
Solution provided by Codio :