Skip to content

Instantly share code, notes, and snippets.

@Kornel
Last active February 4, 2016 14:18
Show Gist options
  • Save Kornel/69caf8df590462d07cea to your computer and use it in GitHub Desktop.
Save Kornel/69caf8df590462d07cea to your computer and use it in GitHub Desktop.
Recursive cowsay inception - random cow at every step
#!/usr/bin/env bash
COWS_PATH="/usr/local/share/cows"
COW_FILES=($(ls $COWS_PATH))
COWS=${#COW_FILES[@]}
rand_cow() {
#RAND_IDX=$(($RANDOM % $COWS))
RAND_IDX=$((`od -vAn -N4 -tu4 < /dev/urandom` % $COWS))
WHICH=`basename ${COW_FILES[$RAND_IDX]} .cow`
echo $WHICH
}
cow() {
N=$1
RES=$(echo "$2" | cowsay -n -f $(rand_cow))
while [ $N -ge 1 ]
do
RES=$(echo "$RES" | cowsay -n -f $(rand_cow))
N=$[$N - 1]
done
echo "$RES"
}
if [ $# -le 1 ]
then
NAME=`basename "$0"`
echo "Usage: ./${NAME} num-levels text"
echo "Example: ./${NAME} 10 Heyy"
else
cow $1 $2
fi
@Kornel
Copy link
Author

Kornel commented Feb 4, 2016

➜  ~  ./recursive-cowsay.sh 4 Cowsay!                                                                                                                                                               [1/9823]
 _________________________________________________
/  _____________________________________________  \
| /  _________________________________________  \ |
| | /  _____________________________________  \ | |
| | | /  _________                          \ | | |
| | | | < Cowsay! >                         | | | |
| | | |  ---------                          | | | |
| | | |     \                               | | | |
| | | |      \                              | | | |
| | | |     ^__^         /                  | | | |
| | | |     (oo)\_______/  _________        | | | |
| | | |     (__)\       )=(  ____|_ \_____  | | | |
| | | |         ||----w |  \ \     \_____ | | | | |
| | | \         ||     ||   ||           || / | | |
| | |  -------------------------------------  | | |
| | |    \                                    | | |
| | |     \                                   | | |
| | |     ____                                | | |
| | |    /# /_\_                              | | |
| | |   |  |/o\o\                             | | |
| | |   |  \\_/_/                             | | |
| | |  / |_   |                               | | |
| | | |  ||\_ ~|                              | | |
| | | |  ||| \/                               | | |
| | | |  |||_                                 | | |
| | |  \//  |                                 | | |
| | |   ||  |                                 | | |
| | |   ||_  \                                | | |
| | |   \_|  o|                               | | |
| | |   /\___/                                | | |
| | |  /  ||||__                              | | |
| | \     (___)_)                             / | |
| |  -----------------------------------------  | |
| |        \    ____                            | |
| |         \  /    \                           | |
| |           | ^__^ |                          | |
| |           | (oo) |______                    | |
| |           | (__) |      )\/\                | |
| |            \____/|----w |                   | |
| |                 ||     ||                   | |
| |                                             | |
| \                  Moofasa                    / |
|  ---------------------------------------------  |
|      \                                          |
|       \                                         |
|           oO)-.                       .-(Oo     |
|          /__  _\                     /_  __\    |
|          \  \(  |     ()~()         |  )/  /    |
|           \__|\ |    (-___-)        | /|__/     |
\           '  '--'    ==`-'==        '--'  '     /
 -------------------------------------------------
  \            .    .     .
   \      .  . .     `  ,
    \    .; .  : .' :  :  : .
     \   i..`: i` i.i.,i  i .
      \   `,--.|i |i|ii|ii|i:
           UooU\.'@@@@@@`.||'
           \__/(@@@@@@@@@@)'
                (@@@@@@@@)
                `YY~~~~YY'
                 ||    ||

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