Skip to content

Instantly share code, notes, and snippets.

@jackinloadup
Created December 7, 2010 20:04
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackinloadup/732325 to your computer and use it in GitHub Desktop.
Save jackinloadup/732325 to your computer and use it in GitHub Desktop.
bash file to generate a fortune from a random cowsay character
#!/bin/bash
cows[1]=beavis.zen
cows[2]=bong
cows[3]=bud-frogs
cows[4]=bunny
cows[5]=cheese
cows[6]=cower
cows[7]=daemon
cows[8]=default
cows[9]=dragon
cows[10]=dragon-and-cow
cows[11]=elephant
cows[12]=elephant-in-snake
cows[13]=eyes
cows[14]=flaming-sheep
cows[15]=ghostbusters
cows[16]=head-in
cows[17]=hellokitty
cows[18]=kiss
cows[19]=kitty
cows[20]=koala
cows[21]=kosh
cows[22]=luke-koala
cows[23]=meow
cows[24]=milk
cows[25]=moofasa
cows[26]=moose
cows[27]=mutilated
cows[28]=ren
cows[29]=satanic
cows[30]=sheep
cows[31]=skeleton
cows[32]=small
cows[33]=sodomized
cows[34]=stegosaurus
cows[35]=stimpy
cows[36]=supermilker
cows[37]=surgery
cows[38]=telebears
cows[39]=three-eyes
cows[40]=turkey
cows[41]=turtle
cows[42]=tux
cows[43]=udder
cows[44]=vader
cows[45]=vader-koala
cows[46]=www
declare -i MAX=${#cows[@]}
if [ ! $MAX -gt 0 ]; then
MAX=6
fi
cowsay -f ${cows[$[ ( $RANDOM % $MAX ) + 1 ]]} `fortune`
@jackinloadup
Copy link
Author

Suggestions welcome

@rezarahimi
Copy link

fortune | cowsay -f ls /usr/share/cowsay/cows/ | shuf -n 1

@s4mpl3d
Copy link

s4mpl3d commented Apr 12, 2017

fortune | cowsay -f $(ls /usr/share/cowsay/cows/ | shuf -n 1)

@emanresusername
Copy link

i do this in my .zlogin

function randomsay() {
    cows=(`cowsay -l | grep -v '/'`)
    cow=${cows[$RANDOM % ${#cows[@]} ]}
    cowsay -f $cow "$@"
}

@soberstadt
Copy link

On Mac (cowsay -l returns a very inconvenient format):

function randomsay() {
  cow=(`cowsay -l | tail -n +2 | tr  " "  "\n" | sort -R | head -n 1`)
  cowsay -f $cow "$@"
}

My dotfile entry

@Pedro-Mendes
Copy link

Hey guys, how are you?

I just found this command:
fortune -a | cow$(shuf -n1 -e say think) -f $(ls /usr/share/cowsay/cows/ | shuf -n1)

It works like a charm!
source: https://ubuntuforums.org/showthread.php?t=1661545

@JafarAkhondali
Copy link

Yes ls thing works and looks cleaner, it'll make another IO operation too.
You can filter out some of dirty cows using this gist xD

@crozone
Copy link

crozone commented Nov 10, 2019

cowsay -f "$(cowsay -l | sed '1d' | tr ' ' '\n' | sort -R | head -1)"

This avoids the need to ls the directory directly, just in case the path ever changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment