Skip to content

Instantly share code, notes, and snippets.

@populov
Last active August 22, 2018 19:14
Show Gist options
  • Select an option

  • Save populov/89028ee3c6c4a2123697da8d2e509e33 to your computer and use it in GitHub Desktop.

Select an option

Save populov/89028ee3c6c4a2123697da8d2e509e33 to your computer and use it in GitHub Desktop.
Fortune + Cowsay with random cows
#!/bin/bash
# First install fortune and cowsay:
# see http://manpages.ubuntu.com/manpages/bionic/en/man6/cowsay.6.html
# and http://manpages.ubuntu.com/manpages/bionic/man6/fortune.6.html
# $ sudo apt-get install fortune cowsay
# and some collection of fortunes. You can find available packages:
# $ apt search fortunes
# for example:
# $ sudo apt-get install fortunes fortunes-off fortunes-ru
# now run what.sh
COWS=/usr/share/cowsay/cows
cows=""
for cow in $(ls -1 $COWS/*); do
cows="$cows $(basename $cow | sed 's/.cow$//')"
done
cows=($cows)
num_cows=${#cows[*]}
cow="${cows[$(( RANDOM % num_cows))]}"
fortune | cowsay -f $cow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment