I am trying to write a script which works out who should be doing the cooking in a team of 4. The script takes the week of the year and divides it by 4. If there is no decimal value, it is Sandra's turn. If it contains .25, it is Christina's turn. If it contains .5, it is Zack's turn. If it contains .75, it is Peter's turn.
#!/bin/bash
# Script to check whose turn it is to cook
let week=$(date +%W)
echo "Current week of the year is $week"
let teamsize=4
counter=`echo "$week/$teamsize"|bc -l`
echo "Current week's counter is $counter"
if [[ "$counter" = ^[0-9]*\.0*$ ]]
then echo "Sandra's turn"
elif [[ "$counter" = ^[0-9]*\.250*$ ]]
then echo "Christina's turn"
elif [[ "$counter" = ^[0-9]*\.50*$ ]]
then echo "Zack's turn"
elif [[ "$counter" = ^[0-9]*\.750*$ ]]
then echo "Peter's turn"
else echo "No cook matched!"
fi
For the current week, it is not matching any of the entries. The week of the year is 18 and this is the output:
Current week of the year is 18
Current week's counter is 4.50000000000000000000
No cook matched!
Appreciate any help figuring out how to match the variable counter to the regex number pattern. Thanks.
=~
instead of=
.