I'm trying to create a bash script to display a word of the day (random for each day). I have a dictionary file that on each line has a word and its definition.
I'd like to use date
to get a unique value for each day. Like so
today=$(date '+%Y%m%d') # will return 20160616 (for today)
Now I'd like to use this value to generate a line number for me to grab from the dictionary file.
My dictionary is 86036
lines long so I need to convert $today
to a value between 1
and 86036
.
What is the best way to do this?
Best Answer
A somewhat different solution: Scramble the lines in your text files with a cron job every day. Your script then picks the first line.
Cron job (requires a
sort
that can "sort" data randomly with-R
):Or, if your
cron
understands@daily
(seeman 5 crontab
):Script:
Full paths to
wotd_data.txt
are obviously required.