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 :
#!/bin/bash
echo "Reading Loud and Clear"
##VARIABLES
declare -a tops=('Tshirt' 'V-Neck' 'Sweater' 'cardigan' 'blouse')
declare -a bottoms=('Blue Jeans' 'Black Jeans' 'Black Slacks' 'Skirt' 'Khakis')
declare -a shoes=('Sneakers' 'Flats' 'Heels' 'Oxfords' 'Whatever Feels Good')
declare -a accessories=('Watch' 'Bracelet' 'Necklace' 'Earrings' 'Hat')
declare -a days=("Monday" "Tuesday" "Wednesday" "Thursday" "Friday")
##FUNCTION DEFINITION
selectWardrobe(){
echo "Now selecting weekly wardrobe"
for day in ${days[@]}
do
randomTop=$(( 0 + $RANDOM % 5))
randomBottom=$(( 0 + $RANDOM % 5))
randomShoes=$(( 0 + $RANDOM % 5))
randomAcc1=$(( 0 + $RANDOM % 5))
randomAcc2=$(( 0 + $RANDOM % 5))
echo "On $day you should wear: ${tops[randomTop]}, ${bottoms[randomBottom]}, and ${shoes[randomShoes]}"
echo "Pair with: ${accessories[randomAcc1]} and ${accessories[randomAcc2]}"
echo
done
}
outfitSelection(){
echo "Generating outfit selection for $1 weeks"
workWeek=1
while (( workWeek < $(( $1+1 )) ))
do
echo "Week $workWeek Wardrobe:"
selectWardrobe
(( workWeek++ ))
done
echo Enjoy $1 weeks of outfit selections!
}
##CALLING FUNCTIONS
outfitSelection 4 > monthlyOutfit.txt
while read textline
do
echo $textline
done < /home/codio/workspace/monthlyOutfit.txt