From c2e630de3cbe3dff05fcf93bfe01c05b4ef71b92 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Sun, 28 Feb 2021 21:20:51 -0500 Subject: [PATCH] fortune: add script Simple fortune implementation in awk. Still needs argument parsing. --- fortune | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 fortune diff --git a/fortune b/fortune new file mode 100755 index 0000000..02276e6 --- /dev/null +++ b/fortune @@ -0,0 +1,22 @@ +#!/usr/bin/awk -f +# Fortune implementation in awk + +BEGIN { + "date +%N" | getline time + srand(time) + "grep '%' " ARGV[1] " | wc -l" | getline n + line = int(rand() * n) +} + +/%/ { + if (p) { + exit + } + z++ + next +} + +z == line { + print $0 + p = 1 +} -- 2.39.2