Fix small error where sometimes it return blank, and never return the
last item.
-awk '$1 == "%" {
- sub(/%/, "")
- ++f
+awk '
+BEGIN {
+ f++
+}
+
+$1 == "%" {
+ f++
fortunes[f] = fortunes[f] (length(fortunes[f])?"\n":"") $0
}
END {
"date +%N" | getline time
srand(time)
fortunes[f] = fortunes[f] (length(fortunes[f])?"\n":"") $0
}
END {
"date +%N" | getline time
srand(time)
- print fortunes[int(rand() * f) + 1]
+ print fortunes[int(rand() * f-2) + 2]